forge
Explore
Log in

Don't you dare go Hollow

Per-clip transform and the edith 20 dialect

Browse files at this commit

bde160515ae7e9bc091ad5750b9a8971ccbca003Ahmet Kaan GümüşParent: c90e425684b8a4
  • feat
    • per-clip transform and the edith 20 dialect
Show full message
✨ feat(engine): per-clip transform and the edith 20 dialect

20 changed files +1240 -105

crates/app/src/tests/editing.rsmodified+3 -0
@@ -625,6 +625,7 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() {
625 link: None,625 link: None,
626 eq: None,626 eq: None,
627 color: None,627 color: None,
628+ transform: None,
628 fit: FitPolicy::default(),629 fit: FitPolicy::default(),
629 speed: Speed::NORMAL,630 speed: Speed::NORMAL,
630 };631 };
@@ -998,6 +999,7 @@ fn a_menu_offers_only_what_applies_and_is_drawn_inside_the_window() {
998 link: Some(1),999 link: Some(1),
999 eq: None,1000 eq: None,
1000 color: None,1001 color: None,
1002+ transform: None,
1001 fit: FitPolicy::default(),1003 fit: FitPolicy::default(),
1002 speed: Speed::NORMAL,1004 speed: Speed::NORMAL,
1003 };1005 };
@@ -1631,6 +1633,7 @@ fn a_copied_clip_is_renumbered_or_dropped_when_a_row_leaves_the_library() {
1631 link: None,1633 link: None,
1632 eq: None,1634 eq: None,
1633 color: None,1635 color: None,
1636+ transform: None,
1634 fit: Default::default(),1637 fit: Default::default(),
1635 speed: Default::default(),1638 speed: Default::default(),
1636 };1639 };
crates/app/src/tests/layout.rsmodified+1 -0
@@ -811,6 +811,7 @@ fn a_drop_moves_the_clip_that_was_picked_up_not_its_old_index() {
811 link: None,811 link: None,
812 eq: None,812 eq: None,
813 color: None,813 color: None,
814+ transform: None,
814 fit: FitPolicy::Fit,815 fit: FitPolicy::Fit,
815 speed: Speed::NORMAL,816 speed: Speed::NORMAL,
816 };817 };
crates/app/src/tests/view.rsmodified+1 -0
@@ -157,6 +157,7 @@ fn the_marks_are_every_lane_the_playhead_and_the_start() {
157 link,157 link,
158 eq: None,158 eq: None,
159 color: None,159 color: None,
160+ transform: None,
160 fit: Default::default(),161 fit: Default::default(),
161 speed: Default::default(),162 speed: Default::default(),
162 };163 };
crates/engine/src/decode.rsmodified+49 -4
@@ -17,6 +17,7 @@ use crate::hw::HwSession;
17 use crate::project::Speed;17 use crate::project::Speed;
18 use crate::scale::Composer;18 use crate::scale::Composer;
19 use crate::tonemap::{self, ToneMapper};19 use crate::tonemap::{self, ToneMapper};
20+use crate::transform::TransformParams;
20 21
21 /// One decoded picture, ready to hand to a renderer.22 /// One decoded picture, ready to hand to a renderer.
22 pub struct Frame {23 pub struct Frame {
@@ -176,6 +177,7 @@ struct SpanCmd {
176 start: u32,177 start: u32,
177 end: u32,178 end: u32,
178 color: ColorParams,179 color: ColorParams,
180+ transform: TransformParams,
179 canvas: Composer,181 canvas: Composer,
180 tone: tonemap::Preset,182 tone: tonemap::Preset,
181 /// The clip's own playback speed ([`crate::project::Clip::speed`]), for183 /// The clip's own playback speed ([`crate::project::Clip::speed`]), for
@@ -308,6 +310,7 @@ impl Worker {
308 start: u32,310 start: u32,
309 end: u32,311 end: u32,
310 color: ColorParams,312 color: ColorParams,
313+ transform: TransformParams,
311 canvas: Composer,314 canvas: Composer,
312 tone: tonemap::Preset,315 tone: tonemap::Preset,
313 speed: Speed,316 speed: Speed,
@@ -331,6 +334,7 @@ impl Worker {
331 start,334 start,
332 end,335 end,
333 color,336 color,
337+ transform,
334 canvas,338 canvas,
335 tone,339 tone,
336 speed,340 speed,
@@ -433,6 +437,9 @@ impl DecodeSession {
433 start_frame,437 start_frame,
434 end_frame,438 end_frame,
435 ColorParams::default(),439 ColorParams::default(),
440+ // No clip, no transform either: the file-level API hands back the
441+ // pictures the file holds, untouched.
442+ TransformParams::default(),
436 // No project, no canvas: the file-level API hands back the443 // No project, no canvas: the file-level API hands back the
437 // pictures the file holds, at the size it holds them.444 // pictures the file holds, at the size it holds them.
438 Composer::passthrough(),445 Composer::passthrough(),
@@ -512,6 +519,7 @@ impl DecodeSession {
512 start_frame: u32,519 start_frame: u32,
513 len: u32,520 len: u32,
514 color: ColorParams,521 color: ColorParams,
522+ transform: TransformParams,
515 canvas: Composer,523 canvas: Composer,
516 ) -> crate::Result<FrameStream> {524 ) -> crate::Result<FrameStream> {
517 let still = Still::open(path)?;525 let still = Still::open(path)?;
@@ -538,6 +546,7 @@ impl DecodeSession {
538 // the project is watching.546 // the project is watching.
539 let first = Render::new(547 let first = Render::new(
540 color,548 color,
549+ transform,
541 ColorDescription::default(),550 ColorDescription::default(),
542 canvas,551 canvas,
543 tonemap::Preset::default(),552 tonemap::Preset::default(),
@@ -610,6 +619,7 @@ impl DecodeSession {
610 start_frame: u32,619 start_frame: u32,
611 end_frame: u32,620 end_frame: u32,
612 color: ColorParams,621 color: ColorParams,
622+ transform: TransformParams,
613 canvas: Composer,623 canvas: Composer,
614 tone: tonemap::Preset,624 tone: tonemap::Preset,
615 ) -> crate::Result<(VideoMeta, FrameStream)> {625 ) -> crate::Result<(VideoMeta, FrameStream)> {
@@ -650,6 +660,7 @@ impl DecodeSession {
650 start_frame,660 start_frame,
651 end_frame,661 end_frame,
652 color,662 color,
663+ transform,
653 canvas,664 canvas,
654 tone,665 tone,
655 // A file-level open has no clip and no speed to skip frames666 // A file-level open has no clip and no speed to skip frames
@@ -677,6 +688,7 @@ impl DecodeSession {
677 start_frame: u32,688 start_frame: u32,
678 end_frame: u32,689 end_frame: u32,
679 color: ColorParams,690 color: ColorParams,
691+ transform: TransformParams,
680 canvas: Composer,692 canvas: Composer,
681 tone: tonemap::Preset,693 tone: tonemap::Preset,
682 speed: Speed,694 speed: Speed,
@@ -687,6 +699,7 @@ impl DecodeSession {
687 start_frame,699 start_frame,
688 end_frame,700 end_frame,
689 color,701 color,
702+ transform,
690 canvas,703 canvas,
691 tone,704 tone,
692 speed,705 speed,
@@ -710,6 +723,7 @@ fn span_worker(
710 start_frame: u32,723 start_frame: u32,
711 end_frame: u32,724 end_frame: u32,
712 color: ColorParams,725 color: ColorParams,
726+ transform: TransformParams,
713 canvas: Composer,727 canvas: Composer,
714 tone: tonemap::Preset,728 tone: tonemap::Preset,
715 speed: Speed,729 speed: Speed,
@@ -740,6 +754,7 @@ fn span_worker(
740 start: start_frame,754 start: start_frame,
741 end: end_frame,755 end: end_frame,
742 color,756 color,
757+ transform,
743 canvas,758 canvas,
744 tone,759 tone,
745 speed,760 speed,
@@ -919,6 +934,7 @@ fn run_span(
919 start,934 start,
920 end,935 end,
921 color,936 color,
937+ transform,
922 canvas,938 canvas,
923 tone,939 tone,
924 speed,940 speed,
@@ -947,7 +963,7 @@ fn run_span(
947 // The stream's own colour and peak brightness: properties of the stream, so963 // The stream's own colour and peak brightness: properties of the stream, so
948 // neither can change while one range decodes -- but the grade, the canvas964 // neither can change while one range decodes -- but the grade, the canvas
949 // and the rendition are the *span's*, so this is built per span.965 // and the rendition are the *span's*, so this is built per span.
950- let mut render = Render::new(color, opened.meta.color, canvas, tone, opened.peak);966+ let mut render = Render::new(color, transform, opened.meta.color, canvas, tone, opened.peak);
951 if let Some(reused) = opened.position_hw(path, start) {967 if let Some(reused) = opened.position_hw(path, start) {
952 // Cancelled during the init (or the seek): leave without decoding.968 // Cancelled during the init (or the seek): leave without decoding.
953 if abort.hit() {969 if abort.hit() {
@@ -1007,6 +1023,9 @@ fn run_span(
1007 /// project resolution, byte for byte and allocation for allocation.1023 /// project resolution, byte for byte and allocation for allocation.
1008 struct Render {1024 struct Render {
1009 color: ColorParams,1025 color: ColorParams,
1026+ /// This clip's placement, on top of whatever the canvas's own fit policy
1027+ /// already does ([`crate::scale::Composer::place_transformed`]).
1028+ transform: TransformParams,
1010 /// What the source's samples mean -- the stream's own matrix and range,1029 /// What the source's samples mean -- the stream's own matrix and range,
1011 /// which is what the conversion below is done in rather than the BT.601 it1030 /// which is what the conversion below is done in rather than the BT.601 it
1012 /// used to assume of every file.1031 /// used to assume of every file.
@@ -1021,6 +1040,10 @@ struct Render {
1021 /// across the worker's whole range. Empty unless the clip needs one: it is1040 /// across the worker's whole range. Empty unless the clip needs one: it is
1022 /// tone-mapped in place, graded in place, or both.1041 /// tone-mapped in place, graded in place, or both.
1023 graded: (Vec<u8>, Vec<u8>, Vec<u8>),1042 graded: (Vec<u8>, Vec<u8>, Vec<u8>),
1043+ /// Where [`Composer::place_transformed`]'s owned picture lands, so a
1044+ /// transformed frame's planes live as long as `self` -- matching what
1045+ /// [`Composer::place`] already hands back by borrowing `self.canvas`.
1046+ placed: (Vec<u8>, Vec<u8>, Vec<u8>),
1024 }1047 }
1025 1048
1026 /// What [`Render::frame`] converts a tone-mapped picture in: the tone map's1049 /// What [`Render::frame`] converts a tone-mapped picture in: the tone map's
@@ -1038,6 +1061,7 @@ impl Render {
1038 /// reference rendition reads (see [`tonemap::Preset`]).1061 /// reference rendition reads (see [`tonemap::Preset`]).
1039 fn new(1062 fn new(
1040 color: ColorParams,1063 color: ColorParams,
1064+ transform: TransformParams,
1041 desc: ColorDescription,1065 desc: ColorDescription,
1042 canvas: Composer,1066 canvas: Composer,
1043 preset: tonemap::Preset,1067 preset: tonemap::Preset,
@@ -1045,6 +1069,7 @@ impl Render {
1045 ) -> Self {1069 ) -> Self {
1046 Self {1070 Self {
1047 color,1071 color,
1072+ transform,
1048 desc,1073 desc,
1049 canvas,1074 canvas,
1050 // corner-cut: the ceiling is that the map reads limited-range codes1075 // corner-cut: the ceiling is that the map reads limited-range codes
@@ -1058,6 +1083,7 @@ impl Render {
1058 Transfer::Hlg => Some(ToneMapper::new(tonemap::Transfer::Hlg, preset, peak)),1083 Transfer::Hlg => Some(ToneMapper::new(tonemap::Transfer::Hlg, preset, peak)),
1059 },1084 },
1060 graded: (Vec::new(), Vec::new(), Vec::new()),1085 graded: (Vec::new(), Vec::new(), Vec::new()),
1086+ placed: (Vec::new(), Vec::new(), Vec::new()),
1061 }1087 }
1062 }1088 }
1063 1089
@@ -1071,6 +1097,12 @@ impl Render {
1071 height: u32,1097 height: u32,
1072 ) -> Frame {1098 ) -> Frame {
1073 let passthrough = self.canvas.is_passthrough(width, height);1099 let passthrough = self.canvas.is_passthrough(width, height);
1100+ // A transform still has a picture to place even where the canvas
1101+ // itself would hand this size back untouched -- moving, scaling,
1102+ // rotating or cropping a passthrough-sized clip is still a placement,
1103+ // and must not be silently dropped by the fused conversion below.
1104+ let transform_active = !self.transform.is_identity();
1105+ let skip_placement = passthrough && !transform_active;
1074 // Everything that has to happen to the samples before the canvas sees1106 // Everything that has to happen to the samples before the canvas sees
1075 // them, on one copy: the tone map (HDR streams only) and, unless the1107 // them, on one copy: the tone map (HDR streams only) and, unless the
1076 // conversion below can fuse it, the grade. An SDR stream that is either1108 // conversion below can fuse it, the grade. An SDR stream that is either
@@ -1080,7 +1112,8 @@ impl Render {
1080 // picture a viewer is shown, so its brightness and saturation mean what1112 // picture a viewer is shown, so its brightness and saturation mean what
1081 // they say in the SDR the tone map just produced, not in the 10-stop1113 // they say in the SDR the tone map just produced, not in the 10-stop
1082 // HDR the file was in.1114 // HDR the file was in.
1083- let (y, u, v, desc) = if self.tone.is_some() || (!passthrough && !self.color.is_identity())1115+ let (y, u, v, desc) = if self.tone.is_some()
1116+ || (!skip_placement && !self.color.is_identity())
1084 {1117 {
1085 let (gy, gu, gv) = &mut self.graded;1118 let (gy, gu, gv) = &mut self.graded;
1086 gy.clear();1119 gy.clear();
@@ -1104,7 +1137,7 @@ impl Render {
1104 } else {1137 } else {
1105 (y, u, v, self.desc)1138 (y, u, v, self.desc)
1106 };1139 };
1107- if passthrough {1140+ if skip_placement {
1108 return Frame {1141 return Frame {
1109 index,1142 index,
1110 width,1143 width,
@@ -1120,7 +1153,15 @@ impl Render {
1120 ),1153 ),
1121 };1154 };
1122 }1155 }
1123- let (y, u, v, width, height) = self.canvas.place(y, u, v, width, height);1156+ let (y, u, v, width, height) = if transform_active {
1157+ let (py, pu, pv, w, h) = self
1158+ .canvas
1159+ .place_transformed(y, u, v, width, height, &self.transform);
1160+ self.placed = (py, pu, pv);
1161+ (&self.placed.0[..], &self.placed.1[..], &self.placed.2[..], w, h)
1162+ } else {
1163+ self.canvas.place(y, u, v, width, height)
1164+ };
1124 Frame {1165 Frame {
1125 index,1166 index,
1126 width,1167 width,
@@ -1384,6 +1425,7 @@ mod tests {
1384 0,1425 0,
1385 u32::MAX,1426 u32::MAX,
1386 ColorParams::default(),1427 ColorParams::default(),
1428+ TransformParams::default(),
1387 Composer::passthrough(),1429 Composer::passthrough(),
1388 tonemap::Preset::default(),1430 tonemap::Preset::default(),
1389 Speed::NORMAL,1431 Speed::NORMAL,
@@ -1405,6 +1447,7 @@ mod tests {
1405 0,1447 0,
1406 u32::MAX,1448 u32::MAX,
1407 ColorParams::default(),1449 ColorParams::default(),
1450+ TransformParams::default(),
1408 Composer::passthrough(),1451 Composer::passthrough(),
1409 tonemap::Preset::default(),1452 tonemap::Preset::default(),
1410 )1453 )
@@ -1453,6 +1496,7 @@ mod tests {
1453 0,1496 0,
1454 u32::MAX,1497 u32::MAX,
1455 ColorParams::default(),1498 ColorParams::default(),
1499+ TransformParams::default(),
1456 Composer::passthrough(),1500 Composer::passthrough(),
1457 tonemap::Preset::default(),1501 tonemap::Preset::default(),
1458 Speed::NORMAL,1502 Speed::NORMAL,
@@ -1536,6 +1580,7 @@ mod tests {
1536 0,1580 0,
1537 u32::MAX,1581 u32::MAX,
1538 ColorParams::default(),1582 ColorParams::default(),
1583+ TransformParams::default(),
1539 Composer::passthrough(),1584 Composer::passthrough(),
1540 tonemap::Preset::default(),1585 tonemap::Preset::default(),
1541 )1586 )
crates/engine/src/edith.rsmodified+304 -59
@@ -16,9 +16,10 @@
16 //! subtitle 3 test_av.mp416 //! subtitle 3 test_av.mp4
17 //! eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk17 //! eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk
18 //! color 0.1:1.2:0.9:-0.318 //! color 0.1:1.2:0.9:-0.3
19-//! video 1 0 0 120 0 0 0 0 fit 1000 0 019+//! transform 0.1:-0.1:1.5:90.0:0.0:0.0:0.0:0.0
20-//! audio 1 0 0 120 0 0 0 - fit 1000 30 3020+//! video 1 0 0 120 0 0 0 0 fit 1000 0 0 0 -
21-//! video 2 120 0 120 1 - - - fill 2000 0 021+//! 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
22 //! audio 223 //! audio 2
23 //! sub 1 0 60 0 500000 150000024 //! sub 1 0 60 0 500000 1500000
24 //! sub 225 //! sub 2
@@ -109,8 +110,16 @@
109 //! ([`crate::color::ColorParams`]), named by position exactly as an eq line is110 //! ([`crate::color::ColorParams`]), named by position exactly as an eq line is
110 //! -- the first colour line is color 0 -- printed and refused by the same rules.111 //! -- the first colour line is color 0 -- printed and refused by the same rules.
111 //!112 //!
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+//!
112 //! A lane line is `<kind> <lane> <start> <in> <out> <source> <link> <eq>120 //! 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 number121+//! <color> <fit> <speed> <fade_in> <fade_out> <transition_out> <transform>`:
122+//! which lane the clip is on -- its kind and its 1-based number
114 //! among the lanes of that kind, the [`crate::project::Lane::label`] a header123 //! among the lanes of that kind, the [`crate::project::Lane::label`] a header
115 //! column shows -- then where the clip sits on the timeline, the half-open124 //! column shows -- then where the clip sits on the timeline, the half-open
116 //! source range it plays, the file it plays from, its group id, the eq line it125 //! source range it plays, the file it plays from, its group id, the eq line it
@@ -120,9 +129,12 @@
120 //! in thousandths of real time ([`crate::project::Speed`], `1000` for a clip129 //! in thousandths of real time ([`crate::project::Speed`], `1000` for a clip
121 //! nobody has speeded), and finally its ramp up from silence and ramp down to130 //! nobody has speeded), and finally its ramp up from silence and ramp down to
122 //! it, in timeline frames ([`crate::project::Clip::fade_in`],131 //! it, in timeline frames ([`crate::project::Clip::fade_in`],
123-//! [`crate::project::Clip::fade_out`], `0 0` for a clip nobody has faded), and132+//! [`crate::project::Clip::fade_out`], `0 0` for a clip nobody has faded), its
124-//! finally its cross-dissolve into whatever abuts its end133+//! cross-dissolve into whatever abuts its end
125-//! ([`crate::project::Clip::transition_out`], `0` for a hard cut).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`]).
126 //! Timeline placement is138 //! Timeline placement is
127 //! explicit, so a *gap* is simply a stretch no line covers -- there is nothing139 //! explicit, so a *gap* is simply a stretch no line covers -- there is nothing
128 //! to write for one, and nothing that can disagree about its length. The `<in>`140 //! to write for one, and nothing that can disagree about its length. The `<in>`
@@ -148,7 +160,11 @@
148 //! track 3 of a two-track palette is refused here, as a clip naming a source160 //! track 3 of a two-track palette is refused here, as a clip naming a source
149 //! that is not there is.161 //! that is not there is.
150 //!162 //!
151-//! **Version 17** was this without the clip's two fade fields: such a project163+//! **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
152 //! holds no clip anyone has faded, which is what a `0 0` pair still means.168 //! holds no clip anyone has faded, which is what a `0 0` pair still means.
153 //! **Version 15** was this without the caption's group field: such a project169 //! **Version 15** was this without the caption's group field: such a project
154 //! holds captions no hand ever grouped, which is every caption there could be.170 //! holds captions no hand ever grouped, which is every caption there could be.
@@ -187,7 +203,7 @@
187 //! nothing, and an older one plays everything at real time, and an older one203 //! nothing, and an older one plays everything at real time, and an older one
188 //! mixes flat, and an older one shows no subtitles, and an older one is shown204 //! mixes flat, and an older one shows no subtitles, and an older one is shown
189 //! in the reference rendition, and an older one places none of the words it205 //! in the reference rendition, and an older one places none of the words it
190-//! names -- and saving any of them writes v18. An older206+//! names -- and saving any of them writes v20. An older
191 //! reader refuses a newer file by name.207 //! reader refuses a newer file by name.
192 //!208 //!
193 //! Text because an edit list is a few integers and a path, and a path is209 //! Text because an edit list is a few integers and a path, and a path is
@@ -220,10 +236,12 @@ use crate::limiter::Limiter;
220 use crate::project::{Clip, Lane, LaneKind, Source, Speed, SubClip};236 use crate::project::{Clip, Lane, LaneKind, Source, Speed, SubClip};
221 use crate::scale::FitPolicy;237 use crate::scale::FitPolicy;
222 use crate::subtitle::SubtitleTrack;238 use crate::subtitle::SubtitleTrack;
239+use crate::transform::TransformParams;
223 240
224 /// What [`save`] writes. Read support goes back to `edith 1`; see the module241 /// What [`save`] writes. Read support goes back to `edith 1`; see the module
225 /// docs for what those dialects looked like.242 /// docs for what those dialects looked like.
226-const MAGIC: &[u8] = b"edith 19";243+const MAGIC: &[u8] = b"edith 20";
244+const MAGIC_V19: &[u8] = b"edith 19";
227 const MAGIC_V18: &[u8] = b"edith 18";245 const MAGIC_V18: &[u8] = b"edith 18";
228 const MAGIC_V17: &[u8] = b"edith 17";246 const MAGIC_V17: &[u8] = b"edith 17";
229 const MAGIC_V16: &[u8] = b"edith 16";247 const MAGIC_V16: &[u8] = b"edith 16";
@@ -265,6 +283,9 @@ pub struct Document {
265 /// The colour table [`Clip::color`] indexes into, in file order. Empty for283 /// The colour table [`Clip::color`] indexes into, in file order. Empty for
266 /// every dialect before v6.284 /// every dialect before v6.
267 pub color: Vec<ColorParams>,285 pub color: Vec<ColorParams>,
286+ /// The transform table [`Clip::transform`] indexes into, in file order.
287+ /// Empty for every dialect before v20.
288+ pub transform: Vec<TransformParams>,
268 /// The project's own picture size. `None` for every dialect before v7 and289 /// The project's own picture size. `None` for every dialect before v7 and
269 /// for a v7 file that leaves it out, which both mean "source 0's picture".290 /// for a v7 file that leaves it out, which both mean "source 0's picture".
270 pub resolution: Option<(u32, u32)>,291 pub resolution: Option<(u32, u32)>,
@@ -333,6 +354,7 @@ pub fn save(
333 subtitles: &[SubtitleTrack],354 subtitles: &[SubtitleTrack],
334 eq: &[EqParams],355 eq: &[EqParams],
335 color: &[ColorParams],356 color: &[ColorParams],
357+ transform: &[TransformParams],
336 resolution: (u32, u32),358 resolution: (u32, u32),
337 fps: Option<f64>,359 fps: Option<f64>,
338 tone: crate::tonemap::Preset,360 tone: crate::tonemap::Preset,
@@ -354,8 +376,8 @@ pub fn save(
354 let result = std::fs::File::create(&part)376 let result = std::fs::File::create(&part)
355 .and_then(|mut f| {377 .and_then(|mut f| {
356 f.write_all(&emit(378 f.write_all(&emit(
357- &dir, sources, lanes, gains, subs, subtitles, eq, color, resolution, fps, tone,379+ &dir, sources, lanes, gains, subs, subtitles, eq, color, transform, resolution,
358- proxy, auto_proxy, encoder, limiter, sample_rate, playhead,380+ fps, tone, proxy, auto_proxy, encoder, limiter, sample_rate, playhead,
359 ))?;381 ))?;
360 f.sync_all()382 f.sync_all()
361 })383 })
@@ -396,6 +418,7 @@ fn emit(
396 subtitles: &[SubtitleTrack],418 subtitles: &[SubtitleTrack],
397 eq: &[EqParams],419 eq: &[EqParams],
398 color: &[ColorParams],420 color: &[ColorParams],
421+ transform: &[TransformParams],
399 resolution: (u32, u32),422 resolution: (u32, u32),
400 fps: Option<f64>,423 fps: Option<f64>,
401 tone: crate::tonemap::Preset,424 tone: crate::tonemap::Preset,
@@ -504,6 +527,16 @@ fn emit(
504 .as_bytes(),527 .as_bytes(),
505 );528 );
506 }529 }
530+ // ...and the transform table, for the same reason and by the same rules.
531+ for p in transform {
532+ out.extend_from_slice(
533+ format!(
534+ "transform {:?}:{:?}:{:?}:{:?}:{:?}:{:?}:{:?}:{:?}\n",
535+ p.pos_x, p.pos_y, p.scale, p.rotate, p.crop_l, p.crop_r, p.crop_t, p.crop_b
536+ )
537+ .as_bytes(),
538+ );
539+ }
507 // Lane by lane rather than interleaved by time: a lane reads as a list, the540 // Lane by lane rather than interleaved by time: a lane reads as a list, the
508 // parser gets its sortedness check for free from the order it is in, and541 // parser gets its sortedness check for free from the order it is in, and
509 // the lanes come back out in the order they are displayed in.542 // the lanes come back out in the order they are displayed in.
@@ -556,9 +589,10 @@ fn emit(
556 let link = c.link.map_or("-".to_string(), |l| l.to_string());589 let link = c.link.map_or("-".to_string(), |l| l.to_string());
557 let eq = c.eq.map_or("-".to_string(), |e| e.to_string());590 let eq = c.eq.map_or("-".to_string(), |e| e.to_string());
558 let color = c.color.map_or("-".to_string(), |e| e.to_string());591 let color = c.color.map_or("-".to_string(), |e| e.to_string());
592+ let transform = c.transform.map_or("-".to_string(), |e| e.to_string());
559 out.extend_from_slice(593 out.extend_from_slice(
560 format!(594 format!(
561- "{keyword} {ord} {} {} {} {} {link} {eq} {color} {} {} {} {} {}\n",595+ "{keyword} {ord} {} {} {} {} {link} {eq} {color} {} {} {} {} {} {transform}\n",
562 c.start,596 c.start,
563 c.in_frame,597 c.in_frame,
564 c.out_frame,598 c.out_frame,
@@ -610,8 +644,10 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
610 // The dialects that wrote a source line without its stream field. Reading644 // The dialects that wrote a source line without its stream field. Reading
611 // one is the whole of what "an old project still opens" means here.645 // one is the whole of what "an old project still opens" means here.
612 let streamless = v1 || first == MAGIC_V2;646 let streamless = v1 || first == MAGIC_V2;
613- // The one that carries a per-clip cross-dissolve into its successor...647+ // The one that carries a per-clip transform (position/scale/rotate/crop)...
614- let v19 = first == MAGIC;648+ let v20 = first == MAGIC;
649+ // ...the one that carries a per-clip cross-dissolve into its successor...
650+ let v19 = v20 || first == MAGIC_V19;
615 // ...the one that carries a per-clip fade envelope...651 // ...the one that carries a per-clip fade envelope...
616 let v18 = v19 || first == MAGIC_V18;652 let v18 = v19 || first == MAGIC_V18;
617 // ...the one that carries an explicit sound rate...653 // ...the one that carries an explicit sound rate...
@@ -668,6 +704,10 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
668 // Nothing before v5 equalizes anything, and nothing before v6 grades.704 // Nothing before v5 equalizes anything, and nothing before v6 grades.
669 eq: Vec::new(),705 eq: Vec::new(),
670 color: Vec::new(),706 color: Vec::new(),
707+ // Nothing before v20 places any clip anywhere but its fit policy's own
708+ // spot: the identity transform is what leaving a clip's index out
709+ // still means.
710+ transform: Vec::new(),
671 // Nothing before v7 has a resolution of its own: source 0's picture is711 // Nothing before v7 has a resolution of its own: source 0's picture is
672 // what those projects were, and `None` is how the loader is told so.712 // what those projects were, and `None` is how the loader is told so.
673 resolution: None,713 resolution: None,
@@ -972,6 +1012,30 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
972 tint: float(parts[3], n)?,1012 tint: float(parts[3], n)?,
973 });1013 });
974 }1014 }
1015+ b"transform" if v20 => {
1016+ if doc.lanes.iter().any(|(_, clips)| !clips.is_empty()) {
1017+ return Err(format!("line {n}: transform after a clip").into());
1018+ }
1019+ let f = fields(rest, 1, "transform", n)?;
1020+ let parts: Vec<&[u8]> = f[0].split(|&b| b == b':').collect();
1021+ if parts.len() != 8 {
1022+ return Err(format!(
1023+ "line {n}: transform wants 8 fields, found {}",
1024+ parts.len()
1025+ )
1026+ .into());
1027+ }
1028+ doc.transform.push(TransformParams {
1029+ pos_x: float(parts[0], n)?,
1030+ pos_y: float(parts[1], n)?,
1031+ scale: float(parts[2], n)?,
1032+ rotate: float(parts[3], n)?,
1033+ crop_l: float(parts[4], n)?,
1034+ crop_r: float(parts[5], n)?,
1035+ crop_t: float(parts[6], n)?,
1036+ crop_b: float(parts[7], n)?,
1037+ });
1038+ }
975 // v1: one lane, no placement, no groups. Every clip becomes one1039 // v1: one lane, no placement, no groups. Every clip becomes one
976 // grouped video+audio pair laid where the queue reached, which is1040 // grouped video+audio pair laid where the queue reached, which is
977 // what the file always meant.1041 // what the file always meant.
@@ -989,6 +1053,7 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
989 link: Some(doc.lanes[0].1.len() as u32),1053 link: Some(doc.lanes[0].1.len() as u32),
990 eq: None,1054 eq: None,
991 color: None,1055 color: None,
1056+ transform: None,
992 fit: FitPolicy::default(),1057 fit: FitPolicy::default(),
993 speed: Speed::NORMAL,1058 speed: Speed::NORMAL,
994 },1059 },
@@ -1100,16 +1165,18 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
1100 if numbered && rest.is_empty() {1165 if numbered && rest.is_empty() {
1101 continue;1166 continue;
1102 }1167 }
1103- // v18 grew the two fade fields, v19 the transition one, v81168+ // v20 grew the transform field, v18 the two fade fields, v19
1104- // the speed one, v7 the fit one, v6 the colour one and v5 the1169+ // the transition one, v8 the speed one, v7 the fit one, v6
1105- // eq one; every older dialect ends at the link.1170+ // the colour one and v5 the eq one; every older dialect ends
1171+ // at the link.
1106 let want = 51172 let want = 5
1107 + usize::from(v5)1173 + usize::from(v5)
1108 + usize::from(v6)1174 + usize::from(v6)
1109 + usize::from(v7)1175 + usize::from(v7)
1110 + usize::from(v8)1176 + usize::from(v8)
1111 + 2 * usize::from(v18)1177 + 2 * usize::from(v18)
1112- + usize::from(v19);1178+ + usize::from(v19)
1179+ + usize::from(v20);
1113 let f = fields(rest, want, "clip", n)?;1180 let f = fields(rest, want, "clip", n)?;
1114 let in_frame = number(f[1], n)?;1181 let in_frame = number(f[1], n)?;
1115 let out_frame = number(f[2], n)?;1182 let out_frame = number(f[2], n)?;
@@ -1134,6 +1201,12 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
1134 },1201 },
1135 eq: table_index(f.get(5).copied(), doc.eq.len(), "eq", n)?,1202 eq: table_index(f.get(5).copied(), doc.eq.len(), "eq", n)?,
1136 color: table_index(f.get(6).copied(), doc.color.len(), "color", n)?,1203 color: table_index(f.get(6).copied(), doc.color.len(), "color", n)?,
1204+ transform: table_index(
1205+ f.get(12).copied(),
1206+ doc.transform.len(),
1207+ "transform",
1208+ n,
1209+ )?,
1137 fit: fit_policy(f.get(7).copied(), n)?,1210 fit: fit_policy(f.get(7).copied(), n)?,
1138 speed,1211 speed,
1139 },1212 },
@@ -1462,6 +1535,7 @@ mod tests {
1462 &[],1535 &[],
1463 eq,1536 eq,
1464 color,1537 color,
1538+ &[],
1465 resolution,1539 resolution,
1466 None,1540 None,
1467 crate::tonemap::Preset::default(),1541 crate::tonemap::Preset::default(),
@@ -1510,6 +1584,7 @@ mod tests {
1510 &tracks,1584 &tracks,
1511 &[],1585 &[],
1512 &[],1586 &[],
1587+ &[],
1513 (1280, 720),1588 (1280, 720),
1514 None,1589 None,
1515 crate::tonemap::Preset::default(),1590 crate::tonemap::Preset::default(),
@@ -1545,7 +1620,7 @@ mod tests {
1545 video 1 0 0 30 0 - - - fit 1000\n";1620 video 1 0 0 30 0 - - - fit 1000\n";
1546 let old = parse(v9, &dir).expect("v9 still loads");1621 let old = parse(v9, &dir).expect("v9 still loads");
1547 assert_eq!(old.subtitles, Vec::new());1622 assert_eq!(old.subtitles, Vec::new());
1548- assert!(flat(&dir, &old.sources, &old.lanes, old.playhead).starts_with(b"edith 19\n"));1623+ assert!(flat(&dir, &old.sources, &old.lanes, old.playhead).starts_with(b"edith 20\n"));
1549 // ...and the line itself is not a v9 line: a dialect may not be mixed.1624 // ...and the line itself is not a v9 line: a dialect may not be mixed.
1550 let mixed = parse(b"edith 9\nsource 0 a.mp4\nsubtitle - subs.srt\n", &dir)1625 let mixed = parse(b"edith 9\nsource 0 a.mp4\nsubtitle - subs.srt\n", &dir)
1551 .unwrap_err()1626 .unwrap_err()
@@ -1591,6 +1666,7 @@ mod tests {
1591 &[subtitle("/proj/subs.srt", None)],1666 &[subtitle("/proj/subs.srt", None)],
1592 &[],1667 &[],
1593 &[],1668 &[],
1669+ &[],
1594 (1280, 720),1670 (1280, 720),
1595 None,1671 None,
1596 crate::tonemap::Preset::default(),1672 crate::tonemap::Preset::default(),
@@ -1643,6 +1719,7 @@ mod tests {
1643 &[],1719 &[],
1644 &[],1720 &[],
1645 &[],1721 &[],
1722+ &[],
1646 (1280, 720),1723 (1280, 720),
1647 None,1724 None,
1648 crate::tonemap::Preset::default(),1725 crate::tonemap::Preset::default(),
@@ -1707,6 +1784,7 @@ mod tests {
1707 &[],1784 &[],
1708 &[],1785 &[],
1709 &[],1786 &[],
1787+ &[],
1710 (1280, 720),1788 (1280, 720),
1711 None,1789 None,
1712 crate::tonemap::Preset::default(),1790 crate::tonemap::Preset::default(),
@@ -1773,6 +1851,7 @@ mod tests {
1773 &[],1851 &[],
1774 &[],1852 &[],
1775 &[],1853 &[],
1854+ &[],
1776 (1280, 720),1855 (1280, 720),
1777 None,1856 None,
1778 crate::tonemap::Preset::default(),1857 crate::tonemap::Preset::default(),
@@ -1846,6 +1925,7 @@ mod tests {
1846 &[],1925 &[],
1847 &[],1926 &[],
1848 &[],1927 &[],
1928+ &[],
1849 (1280, 720),1929 (1280, 720),
1850 None,1930 None,
1851 crate::tonemap::Preset::default(),1931 crate::tonemap::Preset::default(),
@@ -1912,6 +1992,7 @@ mod tests {
1912 &[],1992 &[],
1913 &[],1993 &[],
1914 &[],1994 &[],
1995+ &[],
1915 (1280, 720),1996 (1280, 720),
1916 None,1997 None,
1917 preset,1998 preset,
@@ -1965,6 +2046,7 @@ mod tests {
1965 link,2046 link,
1966 eq: None,2047 eq: None,
1967 color: None,2048 color: None,
2049+ transform: None,
1968 fit: FitPolicy::default(),2050 fit: FitPolicy::default(),
1969 speed: Speed::NORMAL,2051 speed: Speed::NORMAL,
1970 }2052 }
@@ -2016,10 +2098,10 @@ mod tests {
2016 let bytes = flat(&dir, &sources, &lanes, 12);2098 let bytes = flat(&dir, &sources, &lanes, 12);
2017 assert_eq!(2099 assert_eq!(
2018 String::from_utf8_lossy(&bytes),2100 String::from_utf8_lossy(&bytes),
2019- "edith 19\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\2101+ "edith 20\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\
2020 source 2 /elsewhere/b.mp4\n\2102 source 2 /elsewhere/b.mp4\n\
2021- video 1 0 0 30 0 0 - - fit 1000 0 0 0\nvideo 1 30 10 20 1 1 - - fit 1000 0 0 0\n\2103+ video 1 0 0 30 0 0 - - fit 1000 0 0 0 -\nvideo 1 30 10 20 1 1 - - fit 1000 0 0 0 -\n\
2022- audio 1 0 0 30 0 0 - - fit 1000 0 0 0\n",2104+ audio 1 0 0 30 0 0 - - fit 1000 0 0 0 -\n",
2023 "the file under the project directory is written relative to it, \2105 "the file under the project directory is written relative to it, \
2024 each with the audio stream it plays"2106 each with the audio stream it plays"
2025 );2107 );
@@ -2053,9 +2135,9 @@ mod tests {
2053 let bytes = flat(&dir, &sources, &lanes, 7);2135 let bytes = flat(&dir, &sources, &lanes, 7);
2054 assert_eq!(2136 assert_eq!(
2055 String::from_utf8_lossy(&bytes),2137 String::from_utf8_lossy(&bytes),
2056- "edith 19\nplayhead 7\nresolution 1280 720\nsource 0 a.mp4\n\2138+ "edith 20\nplayhead 7\nresolution 1280 720\nsource 0 a.mp4\n\
2057- video 1 0 0 30 0 4 - - fit 1000 0 0 0\naudio 1\n\2139+ video 1 0 0 30 0 4 - - fit 1000 0 0 0 -\naudio 1\n\
2058- video 2 40 0 10 0 - - - fit 1000 0 0 0\naudio 2 0 0 30 0 4 - - fit 1000 0 0 0\n",2140+ video 2 40 0 10 0 - - - fit 1000 0 0 0 -\naudio 2 0 0 30 0 4 - - fit 1000 0 0 0 -\n",
2059 "an empty lane is a line of its own; everything else is its clips"2141 "an empty lane is a line of its own; everything else is its clips"
2060 );2142 );
2061 let back = parse(&bytes, &dir).expect("parse");2143 let back = parse(&bytes, &dir).expect("parse");
@@ -2173,12 +2255,12 @@ mod tests {
2173 let bytes = emit(&dir, &sources, &lanes, &eq, &[], (1280, 720), 0);2255 let bytes = emit(&dir, &sources, &lanes, &eq, &[], (1280, 720), 0);
2174 assert_eq!(2256 assert_eq!(
2175 String::from_utf8_lossy(&bytes),2257 String::from_utf8_lossy(&bytes),
2176- "edith 19\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\2258+ "edith 20\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
2177 eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\2259 eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\
2178 eq 16777215.0:-0.1:3.918315e-39:hs\n\2260 eq 16777215.0:-0.1:3.918315e-39:hs\n\
2179 eq\n\2261 eq\n\
2180- video 1 0 0 30 0 0 0 - fit 1000 0 0 0\nvideo 1 30 10 20 0 - 1 - fit 1000 0 0 0\n\2262+ video 1 0 0 30 0 0 0 - fit 1000 0 0 0 -\nvideo 1 30 10 20 0 - 1 - fit 1000 0 0 0 -\n\
2181- audio 1 0 0 30 0 0 0 - fit 1000 0 0 0\naudio 1 30 0 10 0 - 2 - fit 1000 0 0 0\n",2263+ audio 1 0 0 30 0 0 0 - fit 1000 0 0 0 -\naudio 1 30 0 10 0 - 2 - fit 1000 0 0 0 -\n",
2182 "the table comes before the clips, and a clip names a line of it"2264 "the table comes before the clips, and a clip names a line of it"
2183 );2265 );
2184 2266
@@ -2289,12 +2371,12 @@ mod tests {
2289 let bytes = emit(&dir, &sources, &lanes, &[], &color, (1280, 720), 0);2371 let bytes = emit(&dir, &sources, &lanes, &[], &color, (1280, 720), 0);
2290 assert_eq!(2372 assert_eq!(
2291 String::from_utf8_lossy(&bytes),2373 String::from_utf8_lossy(&bytes),
2292- "edith 19\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\2374+ "edith 20\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
2293 color 0.1:1.2:0.9:-0.3\n\2375 color 0.1:1.2:0.9:-0.3\n\
2294 color -1e-7:16777215.0:3.918315e-39:-0.0\n\2376 color -1e-7:16777215.0:3.918315e-39:-0.0\n\
2295 color 0.0:1.0:1.0:0.0\n\2377 color 0.0:1.0:1.0:0.0\n\
2296- video 1 0 0 30 0 0 - 0 fit 1000 0 0 0\nvideo 1 30 10 20 0 - - 1 fit 1000 0 0 0\n\2378+ video 1 0 0 30 0 0 - 0 fit 1000 0 0 0 -\nvideo 1 30 10 20 0 - - 1 fit 1000 0 0 0 -\n\
2297- audio 1 0 0 30 0 0 - 0 fit 1000 0 0 0\naudio 1 30 0 10 0 - - 2 fit 1000 0 0 0\n",2379+ audio 1 0 0 30 0 0 - 0 fit 1000 0 0 0 -\naudio 1 30 0 10 0 - - 2 fit 1000 0 0 0 -\n",
2298 "the table comes before the clips, and a clip names a line of it"2380 "the table comes before the clips, and a clip names a line of it"
2299 );2381 );
2300 2382
@@ -2354,9 +2436,9 @@ mod tests {
2354 (1280, 720),2436 (1280, 720),
2355 old.playhead2437 old.playhead
2356 )),2438 )),
2357- "edith 19\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\2439+ "edith 20\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\
2358 eq 80.0:-3.0:0.707:ls\n\2440 eq 80.0:-3.0:0.707:ls\n\
2359- video 1 0 0 30 0 0 0 - fit 1000 0 0 0\naudio 1 0 0 30 0 0 - - fit 1000 0 0 0\n"2441+ video 1 0 0 30 0 0 0 - fit 1000 0 0 0 -\naudio 1 0 0 30 0 0 - - fit 1000 0 0 0 -\n"
2360 );2442 );
2361 }2443 }
2362 2444
@@ -2379,6 +2461,7 @@ mod tests {
2379 link: None,2461 link: None,
2380 eq: None,2462 eq: None,
2381 color: None,2463 color: None,
2464+ transform: None,
2382 fit: FitPolicy::default(),2465 fit: FitPolicy::default(),
2383 speed: Speed::from_permille(permille),2466 speed: Speed::from_permille(permille),
2384 };2467 };
@@ -2395,9 +2478,9 @@ mod tests {
2395 let bytes = emit(&dir, &sources, &lanes, &[], &[], (1280, 720), 0);2478 let bytes = emit(&dir, &sources, &lanes, &[], &[], (1280, 720), 0);
2396 assert_eq!(2479 assert_eq!(
2397 String::from_utf8_lossy(&bytes),2480 String::from_utf8_lossy(&bytes),
2398- "edith 19\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\2481+ "edith 20\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
2399- video 1 0 0 30 0 - - - fit 2000 0 0 0\nvideo 1 15 30 40 0 - - - fit 250 0 0 0\n\2482+ video 1 0 0 30 0 - - - fit 2000 0 0 0 -\nvideo 1 15 30 40 0 - - - fit 250 0 0 0 -\n\
2400- audio 1 0 0 30 0 - - - fit 2000 0 0 0\n",2483+ audio 1 0 0 30 0 - - - fit 2000 0 0 0 -\n",
2401 "the rate is the clip line's last field, in thousandths"2484 "the rate is the clip line's last field, in thousandths"
2402 );2485 );
2403 let back = parse(&bytes, &dir).expect("parse");2486 let back = parse(&bytes, &dir).expect("parse");
@@ -2424,8 +2507,8 @@ mod tests {
2424 (1280, 720),2507 (1280, 720),
2425 old.playhead2508 old.playhead
2426 )),2509 )),
2427- "edith 19\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\2510+ "edith 20\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\
2428- video 1 0 0 30 0 0 - - fit 1000 0 0 0\naudio 1 0 0 30 0 0 - - fit 1000 0 0 0\n"2511+ video 1 0 0 30 0 0 - - fit 1000 0 0 0 -\naudio 1 0 0 30 0 0 - - fit 1000 0 0 0 -\n"
2429 );2512 );
2430 // A rate outside what the editor can set is a corrupt line, by name.2513 // A rate outside what the editor can set is a corrupt line, by name.
2431 let bad = b"edith 8\nsource 0 a.mp4\nvideo 1 0 0 30 0 - - - fit 9000\n";2514 let bad = b"edith 8\nsource 0 a.mp4\nvideo 1 0 0 30 0 - - - fit 9000\n";
@@ -2465,6 +2548,7 @@ mod tests {
2465 link: None,2548 link: None,
2466 eq: None,2549 eq: None,
2467 color: None,2550 color: None,
2551+ transform: None,
2468 fit: FitPolicy::default(),2552 fit: FitPolicy::default(),
2469 speed: Speed::NORMAL,2553 speed: Speed::NORMAL,
2470 };2554 };
@@ -2472,8 +2556,8 @@ mod tests {
2472 let bytes = emit(&dir, &sources, &lanes, &[], &[], (1280, 720), 0);2556 let bytes = emit(&dir, &sources, &lanes, &[], &[], (1280, 720), 0);
2473 assert_eq!(2557 assert_eq!(
2474 String::from_utf8_lossy(&bytes),2558 String::from_utf8_lossy(&bytes),
2475- "edith 19\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\2559+ "edith 20\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
2476- video 1 0 0 30 0 - - - fit 1000 5 7 0\n",2560+ video 1 0 0 30 0 - - - fit 1000 5 7 0 -\n",
2477 "the fades are the clip line's last two fields"2561 "the fades are the clip line's last two fields"
2478 );2562 );
2479 let back = parse(&bytes, &dir).expect("parse");2563 let back = parse(&bytes, &dir).expect("parse");
@@ -2515,6 +2599,7 @@ mod tests {
2515 link: None,2599 link: None,
2516 eq: None,2600 eq: None,
2517 color: None,2601 color: None,
2602+ transform: None,
2518 fit: FitPolicy::default(),2603 fit: FitPolicy::default(),
2519 speed: Speed::NORMAL,2604 speed: Speed::NORMAL,
2520 };2605 };
@@ -2522,8 +2607,8 @@ mod tests {
2522 let bytes = emit(&dir, &sources, &lanes, &[], &[], (1280, 720), 0);2607 let bytes = emit(&dir, &sources, &lanes, &[], &[], (1280, 720), 0);
2523 assert_eq!(2608 assert_eq!(
2524 String::from_utf8_lossy(&bytes),2609 String::from_utf8_lossy(&bytes),
2525- "edith 19\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\2610+ "edith 20\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
2526- video 1 0 0 30 0 - - - fit 1000 0 0 9\n",2611+ video 1 0 0 30 0 - - - fit 1000 0 0 9 -\n",
2527 "the dissolve is the clip line's own last field"2612 "the dissolve is the clip line's own last field"
2528 );2613 );
2529 let back = parse(&bytes, &dir).expect("parse");2614 let back = parse(&bytes, &dir).expect("parse");
@@ -2533,6 +2618,164 @@ mod tests {
2533 );2618 );
2534 }2619 }
2535 2620
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+
2536 /// The whole of the v9 bump, the speed test's twin: the mix a project was2779 /// The whole of the v9 bump, the speed test's twin: the mix a project was
2537 /// left at -- every track's own volume and the master limiter -- plus the2780 /// left at -- every track's own volume and the master limiter -- plus the
2538 /// rate it was cut at, all written, all read back as the very numbers, and2781 /// rate it was cut at, all written, all read back as the very numbers, and
@@ -2561,6 +2804,7 @@ mod tests {
2561 &[],2804 &[],
2562 &[],2805 &[],
2563 &[],2806 &[],
2807+ &[],
2564 (1280, 720),2808 (1280, 720),
2565 Some(23.976023976023978),2809 Some(23.976023976023978),
2566 crate::tonemap::Preset::default(),2810 crate::tonemap::Preset::default(),
@@ -2573,10 +2817,10 @@ mod tests {
2573 );2817 );
2574 assert_eq!(2818 assert_eq!(
2575 String::from_utf8_lossy(&bytes),2819 String::from_utf8_lossy(&bytes),
2576- "edith 19\nplayhead 0\nresolution 1280 720\nfps 23.976023976023978\n\2820+ "edith 20\nplayhead 0\nresolution 1280 720\nfps 23.976023976023978\n\
2577 limiter -1.5 on\nsource 0 a.mp4\n\2821 limiter -1.5 on\nsource 0 a.mp4\n\
2578- video 1 0 0 30 0 - - - fit 1000 0 0 0\naudio 1 0 0 30 0 - - - fit 1000 0 0 0\n\2822+ video 1 0 0 30 0 - - - fit 1000 0 0 0 -\naudio 1 0 0 30 0 - - - fit 1000 0 0 0 -\n\
2579- audio 2 0 0 30 0 - - - fit 1000 0 0 0\n\2823+ audio 2 0 0 30 0 - - - fit 1000 0 0 0 -\n\
2580 gain audio 1 3.0\ngain audio 2 -6.5\n",2824 gain audio 1 3.0\ngain audio 2 -6.5\n",
2581 "the mix is lines of its own, the gains after the lanes they name"2825 "the mix is lines of its own, the gains after the lanes they name"
2582 );2826 );
@@ -2605,8 +2849,8 @@ mod tests {
2605 (1280, 720),2849 (1280, 720),
2606 old.playhead2850 old.playhead
2607 )),2851 )),
2608- "edith 19\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\2852+ "edith 20\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\
2609- video 1 0 0 30 0 - - - fit 1000 0 0 0\naudio 1 0 0 30 0 - - - fit 1000 0 0 0\n"2853+ video 1 0 0 30 0 - - - fit 1000 0 0 0 -\naudio 1 0 0 30 0 - - - fit 1000 0 0 0 -\n"
2610 );2854 );
2611 2855
2612 // Each of the three refuses by name, on its own line.2856 // Each of the three refuses by name, on its own line.
@@ -2769,10 +3013,10 @@ mod tests {
2769 assert!(old.eq.is_empty(), "nothing before v5 equalizes anything");3013 assert!(old.eq.is_empty(), "nothing before v5 equalizes anything");
2770 assert_eq!(3014 assert_eq!(
2771 String::from_utf8_lossy(&flat(&dir, &old.sources, &old.lanes, old.playhead)),3015 String::from_utf8_lossy(&flat(&dir, &old.sources, &old.lanes, old.playhead)),
2772- "edith 19\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\3016+ "edith 20\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\
2773 source 2 /elsewhere/b.mp4\n\3017 source 2 /elsewhere/b.mp4\n\
2774- video 1 0 0 30 0 0 - - fit 1000 0 0 0\nvideo 1 30 10 20 1 1 - - fit 1000 0 0 0\n\3018+ video 1 0 0 30 0 0 - - fit 1000 0 0 0 -\nvideo 1 30 10 20 1 1 - - fit 1000 0 0 0 -\n\
2775- audio 1 0 0 30 0 0 - - fit 1000 0 0 0\n"3019+ audio 1 0 0 30 0 0 - - fit 1000 0 0 0 -\n"
2776 );3020 );
2777 // An empty lane's line is still the whole of that lane, eq or no eq.3021 // An empty lane's line is still the whole of that lane, eq or no eq.
2778 let empty = parse(3022 let empty = parse(
@@ -2822,10 +3066,10 @@ mod tests {
2822 let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead);3066 let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead);
2823 assert_eq!(3067 assert_eq!(
2824 String::from_utf8_lossy(&v5),3068 String::from_utf8_lossy(&v5),
2825- "edith 19\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\3069+ "edith 20\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\
2826 source 0 /elsewhere/b.mp4\n\3070 source 0 /elsewhere/b.mp4\n\
2827- video 1 0 0 30 0 0 - - fit 1000 0 0 0\nvideo 1 30 10 20 1 1 - - fit 1000 0 0 0\n\3071+ video 1 0 0 30 0 0 - - fit 1000 0 0 0 -\nvideo 1 30 10 20 1 1 - - fit 1000 0 0 0 -\n\
2828- audio 1 0 0 30 0 0 - - fit 1000 0 0 0\n",3072+ audio 1 0 0 30 0 0 - - fit 1000 0 0 0 -\n",
2829 "a re-saved v2 project differs only by its version, the lane \3073 "a re-saved v2 project differs only by its version, the lane \
2830 numbers, the streams it always meant and an equalizer it has none of"3074 numbers, the streams it always meant and an equalizer it has none of"
2831 );3075 );
@@ -2854,7 +3098,7 @@ mod tests {
2854 // Saved again it is the current version, which round-trips to the3098 // Saved again it is the current version, which round-trips to the
2855 // same document.3099 // same document.
2856 let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead);3100 let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead);
2857- assert!(v5.starts_with(b"edith 19\n"));3101+ assert!(v5.starts_with(b"edith 20\n"));
2858 let again = parse(&v5, &dir).expect("v5 parses");3102 let again = parse(&v5, &dir).expect("v5 parses");
2859 assert_eq!(again.lanes, back.lanes);3103 assert_eq!(again.lanes, back.lanes);
2860 // A dialect may not be mixed: lane lines under v1, `clip` under v2.3104 // A dialect may not be mixed: lane lines under v1, `clip` under v2.
@@ -2950,6 +3194,7 @@ mod tests {
2950 &[],3194 &[],
2951 &[],3195 &[],
2952 &[],3196 &[],
3197+ &[],
2953 (1280, 720),3198 (1280, 720),
2954 None,3199 None,
2955 crate::tonemap::Preset::default(),3200 crate::tonemap::Preset::default(),
@@ -2964,8 +3209,8 @@ mod tests {
2964 let bytes = std::fs::read(&path).expect("read back");3209 let bytes = std::fs::read(&path).expect("read back");
2965 assert_eq!(3210 assert_eq!(
2966 String::from_utf8_lossy(&bytes),3211 String::from_utf8_lossy(&bytes),
2967- "edith 19\nplayhead 0\nresolution 1280 720\nsource 1 a.mp4\n\3212+ "edith 20\nplayhead 0\nresolution 1280 720\nsource 1 a.mp4\n\
2968- video 1 0 0 30 0 - - - fit 1000 0 0 0\naudio 1 0 0 30 0 - - - fit 1000 0 0 0\n"3213+ video 1 0 0 30 0 - - - fit 1000 0 0 0 -\naudio 1 0 0 30 0 - - - fit 1000 0 0 0 -\n"
2969 );3214 );
2970 // Loading rejoins the *given* directory, so the file is reached by the3215 // Loading rejoins the *given* directory, so the file is reached by the
2971 // way the project was opened -- the same file, through the link, still3216 // way the project was opened -- the same file, through the link, still
@@ -3009,10 +3254,10 @@ mod tests {
3009 #[test]3254 #[test]
3010 fn a_wrong_first_line_is_refused_by_name() {3255 fn a_wrong_first_line_is_refused_by_name() {
3011 let dir = PathBuf::from("/proj");3256 let dir = PathBuf::from("/proj");
3012- let err = parse(b"edith 20\nsource 0 a.mp4\nvideo 0 0 5 0 -\n", &dir)3257+ let err = parse(b"edith 21\nsource 0 a.mp4\nvideo 0 0 5 0 -\n", &dir)
3013 .unwrap_err()3258 .unwrap_err()
3014 .to_string();3259 .to_string();
3015- assert_eq!(err, "line 1: unsupported version 20");3260+ assert_eq!(err, "line 1: unsupported version 21");
3016 for junk in [&b""[..], b"{}\n", b"source a.mp4\n"] {3261 for junk in [&b""[..], b"{}\n", b"source a.mp4\n"] {
3017 assert_eq!(3262 assert_eq!(
3018 parse(junk, &dir).unwrap_err().to_string(),3263 parse(junk, &dir).unwrap_err().to_string(),
crates/engine/src/export.rsmodified+38 -3
@@ -82,6 +82,7 @@ use crate::project::{Lane, LaneKind, Project, Rate};
82 use crate::scale::{blend_i420, Composer};82 use crate::scale::{blend_i420, Composer};
83 use crate::subtitle::{Cue, SubtitleTrack};83 use crate::subtitle::{Cue, SubtitleTrack};
84 use crate::tonemap::{self, ToneMapper};84 use crate::tonemap::{self, ToneMapper};
85+use crate::transform::TransformParams;
85 86
86 /// Progress is reported in permille: an atomic integer the render loop can read87 /// Progress is reported in permille: an atomic integer the render loop can read
87 /// without a lock, fine enough for any progress bar.88 /// without a lock, fine enough for any progress bar.
@@ -1098,8 +1099,10 @@ struct Dissolve<'a> {
1098 mapper: Option<&'a ToneMapper>,1099 mapper: Option<&'a ToneMapper>,
1099 remap: Option<(Matrix, Matrix)>,1100 remap: Option<(Matrix, Matrix)>,
1100 grade: Option<crate::color::ColorParams>,1101 grade: Option<crate::color::ColorParams>,
1102+ transform: TransformParams,
1101 canvas: Composer,1103 canvas: Composer,
1102 graded: (Vec<u8>, Vec<u8>, Vec<u8>),1104 graded: (Vec<u8>, Vec<u8>, Vec<u8>),
1105+ transformed: (Vec<u8>, Vec<u8>, Vec<u8>),
1103 }1106 }
1104 1107
1105 /// The track's cues where the *exported* timeline puts them, which is the only1108 /// The track's cues where the *exported* timeline puts them, which is the only
@@ -1658,6 +1661,14 @@ impl CopyPlan {
1658 {1661 {
1659 return None;1662 return None;
1660 }1663 }
1664+ // A moved, scaled, rotated or cropped clip is a different picture
1665+ // than the source's own packets, exactly as a grade is.
1666+ if project
1667+ .composite_transform_at(span.start)
1668+ .is_some_and(|params| !params.is_identity())
1669+ {
1670+ return None;
1671+ }
1661 let path = &entries.get(source)?.path;1672 let path = &entries.get(source)?.path;
1662 if sources.get(source)?.is_none() {1673 if sources.get(source)?.is_none() {
1663 if !crate::demux::is_matroska(path) {1674 if !crate::demux::is_matroska(path) {
@@ -2553,6 +2564,9 @@ fn run(
2553 && project2564 && project
2554 .composite_color_at(span.start)2565 .composite_color_at(span.start)
2555 .is_none_or(|params| params.is_identity())2566 .is_none_or(|params| params.is_identity())
2567+ && project
2568+ .composite_transform_at(span.start)
2569+ .is_none_or(|params| params.is_identity())
2556 && dissolve.is_none();2570 && dissolve.is_none();
2557 let want = untouched.then(|| encoder.dma_want(meta)).flatten();2571 let want = untouched.then(|| encoder.dma_want(meta)).flatten();
2558 // Opened at the file's own frame, which is the only place the2572 // Opened at the file's own frame, which is the only place the
@@ -2582,7 +2596,12 @@ fn run(
2582 // is touched. Scratch outside the frame loop: it is refilled per frame2596 // is touched. Scratch outside the frame loop: it is refilled per frame
2583 // and its allocation survives the whole span.2597 // and its allocation survives the whole span.
2584 let grade = project.composite_color_at(span.start).copied();2598 let grade = project.composite_color_at(span.start).copied();
2599+ let transform = project
2600+ .composite_transform_at(span.start)
2601+ .copied()
2602+ .unwrap_or_default();
2585 let mut graded = (Vec::new(), Vec::new(), Vec::new());2603 let mut graded = (Vec::new(), Vec::new(), Vec::new());
2604+ let mut transformed = (Vec::new(), Vec::new(), Vec::new());
2586 // ...and the canvas it is placed on, which is where a source of another2605 // ...and the canvas it is placed on, which is where a source of another
2587 // resolution becomes a picture at the project's. The same `Composer`2606 // resolution becomes a picture at the project's. The same `Composer`
2588 // playback composes with, given the same policy, so an export is what2607 // playback composes with, given the same policy, so an export is what
@@ -2611,12 +2630,17 @@ fn run(
2611 mapper: b_mapper,2630 mapper: b_mapper,
2612 remap: b_remap,2631 remap: b_remap,
2613 grade: project.composite_color_at(b_start).copied(),2632 grade: project.composite_color_at(b_start).copied(),
2633+ transform: project
2634+ .composite_transform_at(b_start)
2635+ .copied()
2636+ .unwrap_or_default(),
2614 canvas: Composer::new(2637 canvas: Composer::new(
2615 meta.width,2638 meta.width,
2616 meta.height,2639 meta.height,
2617 project.composite_fit_at(b_start),2640 project.composite_fit_at(b_start),
2618 ),2641 ),
2619 graded: (Vec::new(), Vec::new(), Vec::new()),2642 graded: (Vec::new(), Vec::new(), Vec::new()),
2643+ transformed: (Vec::new(), Vec::new(), Vec::new()),
2620 })2644 })
2621 })2645 })
2622 .transpose()?;2646 .transpose()?;
@@ -2704,9 +2728,11 @@ fn run(
2704 width,2728 width,
2705 height,2729 height,
2706 grade,2730 grade,
2731+ transform,
2707 remap,2732 remap,
2708 mapper,2733 mapper,
2709 &mut graded,2734 &mut graded,
2735+ &mut transformed,
2710 &mut canvas,2736 &mut canvas,
2711 )),2737 )),
2712 };2738 };
@@ -2734,8 +2760,9 @@ fn run(
2734 }2760 }
2735 Some(Frame::Pixels(by, bu, bv, bw, bh)) => {2761 Some(Frame::Pixels(by, bu, bv, bw, bh)) => {
2736 let (by, bu, bv, _, _) = place_picture(2762 let (by, bu, bv, _, _) = place_picture(
2737- by, bu, bv, bw, bh, d.grade, d.remap, d.mapper,2763+ by, bu, bv, bw, bh, d.grade, d.transform, d.remap,
2738- &mut d.graded, &mut d.canvas,2764+ d.mapper, &mut d.graded, &mut d.transformed,
2765+ &mut d.canvas,
2739 );2766 );
2740 let idx_in_window = done_here + r - d.tail_start;2767 let idx_in_window = done_here + r - d.tail_start;
2741 let t = dissolve_weight(idx_in_window, d.window);2768 let t = dissolve_weight(idx_in_window, d.window);
@@ -2870,9 +2897,11 @@ fn place_picture<'a>(
2870 width: u32,2897 width: u32,
2871 height: u32,2898 height: u32,
2872 grade: Option<crate::color::ColorParams>,2899 grade: Option<crate::color::ColorParams>,
2900+ transform: TransformParams,
2873 remap: Option<(Matrix, Matrix)>,2901 remap: Option<(Matrix, Matrix)>,
2874 mapper: Option<&ToneMapper>,2902 mapper: Option<&ToneMapper>,
2875 graded: &'a mut (Vec<u8>, Vec<u8>, Vec<u8>),2903 graded: &'a mut (Vec<u8>, Vec<u8>, Vec<u8>),
2904+ transformed: &'a mut (Vec<u8>, Vec<u8>, Vec<u8>),
2876 canvas: &'a mut Composer,2905 canvas: &'a mut Composer,
2877 ) -> (&'a [u8], &'a [u8], &'a [u8], u32, u32) {2906 ) -> (&'a [u8], &'a [u8], &'a [u8], u32, u32) {
2878 // The planes are borrowed from the decoder (and `Black::picture` hands the2907 // The planes are borrowed from the decoder (and `Black::picture` hands the
@@ -2907,7 +2936,13 @@ fn place_picture<'a>(
2907 };2936 };
2908 // Grade first, place second: the grade is the clip's own pixels and the2937 // Grade first, place second: the grade is the clip's own pixels and the
2909 // bars around them are not the clip (see `scale::Composer`).2938 // bars around them are not the clip (see `scale::Composer`).
2910- canvas.place(y, u, v, width, height)2939+ if transform.is_identity() {
2940+ canvas.place(y, u, v, width, height)
2941+ } else {
2942+ let (py, pu, pv, w, h) = canvas.place_transformed(y, u, v, width, height, &transform);
2943+ *transformed = (py, pu, pv);
2944+ (&transformed.0[..], &transformed.1[..], &transformed.2[..], w, h)
2945+ }
2911 }2946 }
2912 2947
2913 /// Which matrix pair a span's samples are rewritten by on the way into a file2948 /// Which matrix pair a span's samples are rewritten by on the way into a file
crates/engine/src/lib.rsmodified+1 -0
@@ -29,6 +29,7 @@ pub(crate) mod map;
29 mod sweep;29 mod sweep;
30 pub(crate) mod stretch;30 pub(crate) mod stretch;
31 pub mod tonemap;31 pub mod tonemap;
32+pub mod transform;
32 pub mod waveform;33 pub mod waveform;
33 34
34 pub use audio::{35 pub use audio::{
crates/engine/src/playback.rsmodified+27 -2
@@ -28,6 +28,7 @@ use crate::demux::{Codec, Demuxer, VideoMeta};
28 use crate::eq::EqParams;28 use crate::eq::EqParams;
29 use crate::project::{Clip, Edge, Lane, LaneKind, Project, Rate, Source, Span, Speed, SubClip};29 use crate::project::{Clip, Edge, Lane, LaneKind, Project, Rate, Source, Span, Speed, SubClip};
30 use crate::scale::{Composer, FitPolicy};30 use crate::scale::{Composer, FitPolicy};
31+use crate::transform::TransformParams;
31 32
32 /// How long the feeder waits out a full ring. The ring holds a second, so this33 /// How long the feeder waits out a full ring. The ring holds a second, so this
33 /// only has to be short next to that; it costs one wakeup per 10 ms of audio.34 /// only has to be short next to that; it costs one wakeup per 10 ms of audio.
@@ -553,6 +554,7 @@ impl PlaybackSession {
553 0,554 0,
554 u32::MAX,555 u32::MAX,
555 ColorParams::default(),556 ColorParams::default(),
557+ TransformParams::default(),
556 Composer::passthrough(),558 Composer::passthrough(),
557 // The default rendition: a file just opened is a project nobody has559 // The default rendition: a file just opened is a project nobody has
558 // picked one for, exactly as it is a project nobody has graded.560 // picked one for, exactly as it is a project nobody has graded.
@@ -624,6 +626,7 @@ impl PlaybackSession {
624 vec![(LaneKind::Video, Vec::new()), (LaneKind::Audio, Vec::new())],626 vec![(LaneKind::Video, Vec::new()), (LaneKind::Audio, Vec::new())],
625 Vec::new(),627 Vec::new(),
626 Vec::new(),628 Vec::new(),
629+ Vec::new(),
627 )?;630 )?;
628 // Onto the emptied mapping: black picture, silence, zero duration.631 // Onto the emptied mapping: black picture, silence, zero duration.
629 session.seek(0.);632 session.seek(0.);
@@ -672,6 +675,7 @@ impl PlaybackSession {
672 link: None,675 link: None,
673 eq: None,676 eq: None,
674 color: None,677 color: None,
678+ transform: None,
675 fit: FitPolicy::default(),679 fit: FitPolicy::default(),
676 speed: Speed::NORMAL,680 speed: Speed::NORMAL,
677 };681 };
@@ -680,6 +684,7 @@ impl PlaybackSession {
680 vec![(LaneKind::Video, Vec::new()), (LaneKind::Audio, vec![clip])],684 vec![(LaneKind::Video, Vec::new()), (LaneKind::Audio, vec![clip])],
681 Vec::new(),685 Vec::new(),
682 Vec::new(),686 Vec::new(),
687+ Vec::new(),
683 )?;688 )?;
684 // Every frame of this timeline is a gap, since no video lane covers689 // Every frame of this timeline is a gap, since no video lane covers
685 // anything: `composite_span_at` says so and the black worker690 // anything: `composite_span_at` says so and the black worker
@@ -759,6 +764,7 @@ impl PlaybackSession {
759 link: None,764 link: None,
760 eq: None,765 eq: None,
761 color: None,766 color: None,
767+ transform: None,
762 fit: FitPolicy::default(),768 fit: FitPolicy::default(),
763 speed: Speed::NORMAL,769 speed: Speed::NORMAL,
764 };770 };
@@ -769,6 +775,7 @@ impl PlaybackSession {
769 vec![(LaneKind::Video, vec![clip]), (LaneKind::Audio, Vec::new())],775 vec![(LaneKind::Video, vec![clip]), (LaneKind::Audio, Vec::new())],
770 Vec::new(),776 Vec::new(),
771 Vec::new(),777 Vec::new(),
778+ Vec::new(),
772 )?;779 )?;
773 let span = project.composite_span_at(0);780 let span = project.composite_span_at(0);
774 // The placeholder the first seek supersedes, opened here for `open`'s781 // The placeholder the first seek supersedes, opened here for `open`'s
@@ -778,6 +785,7 @@ impl PlaybackSession {
778 0,785 0,
779 span.map_or(1, |s| s.len),786 span.map_or(1, |s| s.len),
780 ColorParams::default(),787 ColorParams::default(),
788+ TransformParams::default(),
781 Composer::passthrough(),789 Composer::passthrough(),
782 )?;790 )?;
783 Ok(Self {791 Ok(Self {
@@ -911,6 +919,7 @@ impl PlaybackSession {
911 0,919 0,
912 1,920 1,
913 ColorParams::default(),921 ColorParams::default(),
922+ TransformParams::default(),
914 Composer::passthrough(),923 Composer::passthrough(),
915 )?;924 )?;
916 (meta, stream)925 (meta, stream)
@@ -920,6 +929,7 @@ impl PlaybackSession {
920 0,929 0,
921 u32::MAX,930 u32::MAX,
922 ColorParams::default(),931 ColorParams::default(),
932+ TransformParams::default(),
923 Composer::passthrough(),933 Composer::passthrough(),
924 // The saved rendition, from the document rather than from the934 // The saved rendition, from the document rather than from the
925 // project (which is built below): this placeholder is what the935 // project (which is built below): this placeholder is what the
@@ -1060,7 +1070,8 @@ impl PlaybackSession {
1060 // whole to reach one track: a film whose project names many of its1070 // whole to reach one track: a film whose project names many of its
1061 // tracks is one walk here rather than one per row.1071 // tracks is one walk here rather than one per row.
1062 let subtitles = crate::subtitle::open_all(&doc.subtitles);1072 let subtitles = crate::subtitle::open_all(&doc.subtitles);
1063- let project = Project::from_parts(doc.sources, doc.lanes, doc.eq, doc.color)?1073+ let project =
1074+ Project::from_parts(doc.sources, doc.lanes, doc.eq, doc.color, doc.transform)?
1064 .with_mix(&doc.gains, doc.limiter)1075 .with_mix(&doc.gains, doc.limiter)
1065 .with_tone(doc.tone)1076 .with_tone(doc.tone)
1066 // The palette before what is placed on it: a caption names a row of1077 // The palette before what is placed on it: a caption names a row of
@@ -1353,7 +1364,7 @@ impl PlaybackSession {
1353 if self.project.sources().is_empty() {1364 if self.project.sources().is_empty() {
1354 return Err("this project names no file: there is nothing to save".into());1365 return Err("this project names no file: there is nothing to save".into());
1355 }1366 }
1356- let (sources, lanes, eq, color) = self.project.without_orphan_sources();1367+ let (sources, lanes, eq, color, transform) = self.project.without_orphan_sources();
1357 let playhead = secs_to_frame(self.now(), self.meta.frame_rate)1368 let playhead = secs_to_frame(self.now(), self.meta.frame_rate)
1358 .min(self.project.timeline_frames().saturating_sub(1));1369 .min(self.project.timeline_frames().saturating_sub(1));
1359 crate::edith::save(1370 crate::edith::save(
@@ -1373,6 +1384,7 @@ impl PlaybackSession {
1373 self.project.subtitles(),1384 self.project.subtitles(),
1374 &eq,1385 &eq,
1375 &color,1386 &color,
1387+ &transform,
1376 (self.meta.width, self.meta.height),1388 (self.meta.width, self.meta.height),
1377 // ...and the rate it was cut at, which nothing else in the file1389 // ...and the rate it was cut at, which nothing else in the file
1378 // says: a timeline of stills and songs used to come back at1390 // says: a timeline of stills and songs used to come back at
@@ -1697,6 +1709,10 @@ impl PlaybackSession {
1697 .composite_color_at(start)1709 .composite_color_at(start)
1698 .copied()1710 .copied()
1699 .unwrap_or_default(),1711 .unwrap_or_default(),
1712+ self.project
1713+ .composite_transform_at(start)
1714+ .copied()
1715+ .unwrap_or_default(),
1700 Composer::new(1716 Composer::new(
1701 self.meta.width,1717 self.meta.width,
1702 self.meta.height,1718 self.meta.height,
@@ -1740,6 +1756,11 @@ impl PlaybackSession {
1740 .composite_color_at(start)1756 .composite_color_at(start)
1741 .copied()1757 .copied()
1742 .unwrap_or_default();1758 .unwrap_or_default();
1759+ let transform = self
1760+ .project
1761+ .composite_transform_at(start)
1762+ .copied()
1763+ .unwrap_or_default();
1743 // ...and the canvas it is placed on: the project's resolution1764 // ...and the canvas it is placed on: the project's resolution
1744 // and this clip's own fit policy, constant across the span for1765 // and this clip's own fit policy, constant across the span for
1745 // the reason the grade is. Built where it is handed over rather1766 // the reason the grade is. Built where it is handed over rather
@@ -1778,6 +1799,7 @@ impl PlaybackSession {
1778 start_frame,1799 start_frame,
1779 end_frame,1800 end_frame,
1780 color,1801 color,
1802+ transform,
1781 canvas(),1803 canvas(),
1782 tone,1804 tone,
1783 decode_speed,1805 decode_speed,
@@ -1792,6 +1814,7 @@ impl PlaybackSession {
1792 start_frame,1814 start_frame,
1793 end_frame,1815 end_frame,
1794 color,1816 color,
1817+ transform,
1795 canvas(),1818 canvas(),
1796 tone,1819 tone,
1797 decode_speed,1820 decode_speed,
@@ -2839,6 +2862,7 @@ impl PlaybackSession {
2839 link: None,2862 link: None,
2840 eq: None,2863 eq: None,
2841 color: None,2864 color: None,
2865+ transform: None,
2842 fit: FitPolicy::default(),2866 fit: FitPolicy::default(),
2843 speed: Speed::NORMAL,2867 speed: Speed::NORMAL,
2844 };2868 };
@@ -3721,6 +3745,7 @@ fn matches_timeline(
3721 0,3745 0,
3722 0,3746 0,
3723 ColorParams::default(),3747 ColorParams::default(),
3748+ TransformParams::default(),
3724 Composer::passthrough(),3749 Composer::passthrough(),
3725 // A zero-length range decodes nothing, so no table is built and the3750 // A zero-length range decodes nothing, so no table is built and the
3726 // rendition cannot matter here.3751 // rendition cannot matter here.
crates/engine/src/project.rsmodified+326 -31
@@ -77,6 +77,7 @@ use crate::map::TimelineMap;
77 use std::path::{Path, PathBuf};77 use std::path::{Path, PathBuf};
78 78
79 use crate::color::ColorParams;79 use crate::color::ColorParams;
80+use crate::transform::TransformParams;
80 use crate::eq::EqParams;81 use crate::eq::EqParams;
81 use crate::limiter::{Limiter, db_to_linear};82 use crate::limiter::{Limiter, db_to_linear};
82 use crate::scale::FitPolicy;83 use crate::scale::FitPolicy;
@@ -413,6 +414,11 @@ pub struct Clip {
413 /// plays ungraded. An index for [`Clip::eq`]'s reason, and with the same414 /// plays ungraded. An index for [`Clip::eq`]'s reason, and with the same
414 /// promises: `Copy`, append-only within a session, never dangling.415 /// promises: `Copy`, append-only within a session, never dangling.
415 pub color: Option<u16>,416 pub color: Option<u16>,
417+ /// Index into the project's transform table
418+ /// ([`Project::transform_of`]/[`Project::set_transform`]), or `None` for a
419+ /// clip that plays at its fit policy's own placement. An index for
420+ /// [`Clip::color`]'s reason and with the same promises.
421+ pub transform: Option<u16>,
416 /// How this clip's picture meets a project canvas of another shape422 /// How this clip's picture meets a project canvas of another shape
417 /// ([`crate::scale::FitPolicy`]). Inline rather than a table index like the423 /// ([`crate::scale::FitPolicy`]). Inline rather than a table index like the
418 /// two above: it is one byte with no parameters, so there is nothing for a424 /// two above: it is one byte with no parameters, so there is nothing for a
@@ -856,6 +862,7 @@ pub type Parts = (
856 Vec<(LaneKind, Vec<Clip>)>,862 Vec<(LaneKind, Vec<Clip>)>,
857 Vec<EqParams>,863 Vec<EqParams>,
858 Vec<ColorParams>,864 Vec<ColorParams>,
865+ Vec<TransformParams>,
859 );866 );
860 867
861 /// How many undo steps a project keeps. One gesture is one step, so 100 is past868 /// How many undo steps a project keeps. One gesture is one step, so 100 is past
@@ -877,6 +884,8 @@ pub struct Project {
877 eq: Vec<EqParams>,884 eq: Vec<EqParams>,
878 /// The same, for [`Clip::color`].885 /// The same, for [`Clip::color`].
879 color: Vec<ColorParams>,886 color: Vec<ColorParams>,
887+ /// The same, for [`Clip::transform`].
888+ transform: Vec<TransformParams>,
880 /// Snapshots pushed *before* each successful edit; `undo` pops one. The889 /// Snapshots pushed *before* each successful edit; `undo` pops one. The
881 /// whole lane list, so adding a lane undoes as well. Bounded by890 /// whole lane list, so adding a lane undoes as well. Bounded by
882 /// [`HISTORY_CAP`]: at the cap the oldest step goes.891 /// [`HISTORY_CAP`]: at the cap the oldest step goes.
@@ -923,6 +932,7 @@ impl Project {
923 link: Some(0),932 link: Some(0),
924 eq: None,933 eq: None,
925 color: None,934 color: None,
935+ transform: None,
926 fit: FitPolicy::default(),936 fit: FitPolicy::default(),
927 speed: Speed::NORMAL,937 speed: Speed::NORMAL,
928 };938 };
@@ -933,6 +943,7 @@ impl Project {
933 lanes: LaneData::two_lanes(vec![clip], vec![clip]),943 lanes: LaneData::two_lanes(vec![clip], vec![clip]),
934 eq: Vec::new(),944 eq: Vec::new(),
935 color: Vec::new(),945 color: Vec::new(),
946+ transform: Vec::new(),
936 history: Vec::new(),947 history: Vec::new(),
937 redo: Vec::new(),948 redo: Vec::new(),
938 next_link: 1,949 next_link: 1,
@@ -964,6 +975,7 @@ impl Project {
964 lanes: Vec<(LaneKind, Vec<Clip>)>,975 lanes: Vec<(LaneKind, Vec<Clip>)>,
965 eq: Vec<EqParams>,976 eq: Vec<EqParams>,
966 color: Vec<ColorParams>,977 color: Vec<ColorParams>,
978+ transform: Vec<TransformParams>,
967 ) -> crate::Result<Self> {979 ) -> crate::Result<Self> {
968 if let Some(bad) = eq.iter().position(|p| !finite(p)) {980 if let Some(bad) = eq.iter().position(|p| !finite(p)) {
969 return Err(format!("eq {bad} holds a band that is not a finite number").into());981 return Err(format!("eq {bad} holds a band that is not a finite number").into());
@@ -971,6 +983,9 @@ impl Project {
971 if let Some(bad) = color.iter().position(|p| !color_finite(p)) {983 if let Some(bad) = color.iter().position(|p| !color_finite(p)) {
972 return Err(format!("color {bad} holds a value that is not a finite number").into());984 return Err(format!("color {bad} holds a value that is not a finite number").into());
973 }985 }
986+ if let Some(bad) = transform.iter().position(|p| !transform_finite(p)) {
987+ return Err(format!("transform {bad} holds a value that is not a finite number").into());
988+ }
974 if lanes.is_empty() {989 if lanes.is_empty() {
975 return Err("no lanes at all: that is not a project".into());990 return Err("no lanes at all: that is not a project".into());
976 }991 }
@@ -1034,6 +1049,15 @@ impl Project {
1034 )1049 )
1035 .into());1050 .into());
1036 }1051 }
1052+ if c.transform.is_some_and(|i| usize::from(i) >= transform.len()) {
1053+ return Err(format!(
1054+ "{name} clip at {} names transform {} of {}",
1055+ c.start,
1056+ c.transform.unwrap_or_default(),
1057+ transform.len()
1058+ )
1059+ .into());
1060+ }
1037 }1061 }
1038 if !sorted_disjoint(&data.clips) {1062 if !sorted_disjoint(&data.clips) {
1039 return Err(format!("the {name} lane is out of order or overlaps itself").into());1063 return Err(format!("the {name} lane is out of order or overlaps itself").into());
@@ -1063,6 +1087,7 @@ impl Project {
1063 lanes,1087 lanes,
1064 eq,1088 eq,
1065 color,1089 color,
1090+ transform,
1066 history: Vec::new(),1091 history: Vec::new(),
1067 redo: Vec::new(),1092 redo: Vec::new(),
1068 next_link,1093 next_link,
@@ -1306,6 +1331,7 @@ impl Project {
1306 link: Some(self.new_link()),1331 link: Some(self.new_link()),
1307 eq: None,1332 eq: None,
1308 color: None,1333 color: None,
1334+ transform: None,
1309 fit: FitPolicy::default(),1335 fit: FitPolicy::default(),
1310 speed: Speed::NORMAL,1336 speed: Speed::NORMAL,
1311 };1337 };
@@ -1413,6 +1439,8 @@ impl Project {
1413 let mut eq = Vec::new();1439 let mut eq = Vec::new();
1414 let mut moved_color = vec![None; self.color.len()];1440 let mut moved_color = vec![None; self.color.len()];
1415 let mut color = Vec::new();1441 let mut color = Vec::new();
1442+ let mut moved_transform = vec![None; self.transform.len()];
1443+ let mut transform = Vec::new();
1416 let mut lanes = self.lanes.clone();1444 let mut lanes = self.lanes.clone();
1417 for c in lanes.iter_mut().flat_map(|l| &mut l.clips) {1445 for c in lanes.iter_mut().flat_map(|l| &mut l.clips) {
1418 let old = c.source;1446 let old = c.source;
@@ -1446,6 +1474,17 @@ impl Project {
1446 }1474 }
1447 });1475 });
1448 }1476 }
1477+ if let Some(old) = c.transform.map(usize::from) {
1478+ c.transform = Some(match moved_transform[old] {
1479+ Some(new) => new,
1480+ None => {
1481+ transform.push(self.transform[old]);
1482+ let new = (transform.len() - 1) as u16;
1483+ moved_transform[old] = Some(new);
1484+ new
1485+ }
1486+ });
1487+ }
1449 }1488 }
1450 if sources.is_empty() {1489 if sources.is_empty() {
1451 sources.extend(self.sources.first().cloned());1490 sources.extend(self.sources.first().cloned());
@@ -1459,6 +1498,7 @@ impl Project {
1459 lanes.into_iter().map(|l| (l.kind, l.clips)).collect(),1498 lanes.into_iter().map(|l| (l.kind, l.clips)).collect(),
1460 eq,1499 eq,
1461 color,1500 color,
1501+ transform,
1462 )1502 )
1463 }1503 }
1464 1504
@@ -2303,6 +2343,71 @@ impl Project {
2303 true2343 true
2304 }2344 }
2305 2345
2346+ /// How the clip at `idx` of `lane` is placed, or `None` for one at its fit
2347+ /// policy's own placement (and for an index that is not there) -- what the
2348+ /// renderer and the export ask before they place its picture.
2349+ pub fn transform_of(&self, lane: Lane, idx: usize) -> Option<&TransformParams> {
2350+ self.transform
2351+ .get(usize::from(self.lane(lane).get(idx)?.transform?))
2352+ }
2353+
2354+ /// [`set_color`](Self::set_color)'s twin for [`Clip::transform`]: one undo
2355+ /// step, `false` (and no history) for an index that is not there or a
2356+ /// value that is not finite, and equal settings share a table entry.
2357+ pub fn set_transform(&mut self, lane: Lane, idx: usize, params: Option<TransformParams>) -> bool {
2358+ self.write_transform(lane, idx, params, true)
2359+ }
2360+
2361+ /// [`set_transform`](Self::set_transform) without the undo step, for
2362+ /// [`set_color_live`](Self::set_color_live)'s reason: the samples inside
2363+ /// one drag on a position/scale/rotate/crop control are one undo, not one
2364+ /// per pixel.
2365+ pub fn set_transform_live(
2366+ &mut self,
2367+ lane: Lane,
2368+ idx: usize,
2369+ params: Option<TransformParams>,
2370+ ) -> bool {
2371+ self.write_transform(lane, idx, params, false)
2372+ }
2373+
2374+ fn write_transform(
2375+ &mut self,
2376+ lane: Lane,
2377+ idx: usize,
2378+ params: Option<TransformParams>,
2379+ snapshot: bool,
2380+ ) -> bool {
2381+ if idx >= self.lane(lane).len() {
2382+ return false;
2383+ }
2384+ let slot = match params {
2385+ None => None,
2386+ Some(params) => {
2387+ if !transform_finite(&params) {
2388+ return false;
2389+ }
2390+ Some(match self.transform.iter().position(|p| *p == params) {
2391+ Some(at) => at as u16,
2392+ // corner-cut: the 65535th *distinct* transform of one
2393+ // session is refused rather than silently aliased,
2394+ // exactly as `write_color` refuses the 65535th grade;
2395+ // same upgrade path.
2396+ None if self.transform.len() >= usize::from(u16::MAX) => return false,
2397+ None => {
2398+ self.transform.push(params);
2399+ (self.transform.len() - 1) as u16
2400+ }
2401+ })
2402+ }
2403+ };
2404+ if snapshot {
2405+ self.snapshot();
2406+ }
2407+ self.lane_mut(lane).expect("checked above")[idx].transform = slot;
2408+ true
2409+ }
2410+
2306 /// How fast the clip at `idx` of `lane` plays. [`Speed::NORMAL`] for an2411 /// How fast the clip at `idx` of `lane` plays. [`Speed::NORMAL`] for an
2307 /// index that is not there, which is what every clip starts at anyway.2412 /// index that is not there, which is what every clip starts at anyway.
2308 pub fn speed_of(&self, lane: Lane, idx: usize) -> Speed {2413 pub fn speed_of(&self, lane: Lane, idx: usize) -> Speed {
@@ -2870,6 +2975,14 @@ impl Project {
2870 self.color_of(lane, idx)2975 self.color_of(lane, idx)
2871 }2976 }
2872 2977
2978+ /// [`composite_color_at`](Self::composite_color_at)'s twin for
2979+ /// [`Clip::transform`]: `None` over a gap and for a clip at its fit
2980+ /// policy's own placement.
2981+ pub fn composite_transform_at(&self, timeline_frame: u32) -> Option<&TransformParams> {
2982+ let (lane, idx) = self.composite_clip_at(timeline_frame)?;
2983+ self.transform_of(lane, idx)
2984+ }
2985+
2873 /// How the composite meets the project canvas at `timeline_frame`, so the2986 /// How the composite meets the project canvas at `timeline_frame`, so the
2874 /// picture playback composes and the one an export encodes are placed from2987 /// picture playback composes and the one an export encodes are placed from
2875 /// one answer. `Fit` over a gap, where black is already the canvas.2988 /// one answer. `Fit` over a gap, where black is already the canvas.
@@ -4504,6 +4617,7 @@ impl Project {
4504 lanes: self.lanes.clone(),4617 lanes: self.lanes.clone(),
4505 eq: self.eq.clone(),4618 eq: self.eq.clone(),
4506 color: self.color.clone(),4619 color: self.color.clone(),
4620+ transform: self.transform.clone(),
4507 history: Vec::new(),4621 history: Vec::new(),
4508 redo: Vec::new(),4622 redo: Vec::new(),
4509 next_link: self.next_link,4623 next_link: self.next_link,
@@ -4845,6 +4959,20 @@ fn color_finite(p: &ColorParams) -> bool {
4845 && p.tint.is_finite()4959 && p.tint.is_finite()
4846 }4960 }
4847 4961
4962+/// The same for a transform: [`crate::scale`] clamps a non-finite value to
4963+/// identity at read time, but a value that cannot round-trip has no business
4964+/// reaching the model.
4965+fn transform_finite(p: &TransformParams) -> bool {
4966+ p.pos_x.is_finite()
4967+ && p.pos_y.is_finite()
4968+ && p.scale.is_finite()
4969+ && p.rotate.is_finite()
4970+ && p.crop_l.is_finite()
4971+ && p.crop_r.is_finite()
4972+ && p.crop_t.is_finite()
4973+ && p.crop_b.is_finite()
4974+}
4975+
4848 fn sorted_disjoint(clips: &[Clip]) -> bool {4976 fn sorted_disjoint(clips: &[Clip]) -> bool {
4849 clips.iter().all(|c| c.out_frame > c.in_frame)4977 clips.iter().all(|c| c.out_frame > c.in_frame)
4850 && clips.windows(2).all(|w| w[0].end() <= w[1].start)4978 && clips.windows(2).all(|w| w[0].end() <= w[1].start)
@@ -5197,6 +5325,7 @@ mod tests {
5197 link: None,5325 link: None,
5198 eq: None,5326 eq: None,
5199 color: None,5327 color: None,
5328+ transform: None,
5200 fit: FitPolicy::default(),5329 fit: FitPolicy::default(),
5201 speed: Speed::NORMAL,5330 speed: Speed::NORMAL,
5202 }5331 }
@@ -5224,6 +5353,15 @@ mod tests {
5224 }5353 }
5225 }5354 }
5226 5355
5356+ /// A recognisable placement, `n` telling two of them apart -- [`grade_at`]'s
5357+ /// twin for the transform table.
5358+ fn transform_at(n: u32) -> TransformParams {
5359+ TransformParams {
5360+ pos_x: f64::from(n) as f32 * 0.05,
5361+ ..Default::default()
5362+ }
5363+ }
5364+
5227 /// The `V1`, `A1` lane list a two-lane load hands [`Project::from_parts`].5365 /// The `V1`, `A1` lane list a two-lane load hands [`Project::from_parts`].
5228 fn two(video: Vec<Clip>, audio: Vec<Clip>) -> Vec<(LaneKind, Vec<Clip>)> {5366 fn two(video: Vec<Clip>, audio: Vec<Clip>) -> Vec<(LaneKind, Vec<Clip>)> {
5229 vec![(LaneKind::Video, video), (LaneKind::Audio, audio)]5367 vec![(LaneKind::Video, video), (LaneKind::Audio, audio)]
@@ -6642,6 +6780,9 @@ mod tests {
6642 /// 52 bytes of fields, but the struct's own alignment is 8 (from the6780 /// 52 bytes of fields, but the struct's own alignment is 8 (from the
6643 /// `usize` source and the 8-byte `Option<u32>` link), so an odd number of6781 /// `usize` source and the 8-byte `Option<u32>` link), so an odd number of
6644 /// words after it pads out to the next multiple of 8: 56 bytes total.6782 /// words after it pads out to the next multiple of 8: 56 bytes total.
6783+ /// The transform index is a third `Option<u16>`, same reason as the eq and
6784+ /// colour ones before it -- it lands in bytes already spent on padding, so
6785+ /// the struct still costs 56.
6645 /// This is the assert that says so: a clip that grows a word grows every6786 /// This is the assert that says so: a clip that grows a word grows every
6646 /// undo snapshot and every clipboard copy with it.6787 /// undo snapshot and every clipboard copy with it.
6647 #[test]6788 #[test]
@@ -6667,6 +6808,7 @@ mod tests {
6667 link: None,6808 link: None,
6668 eq: None,6809 eq: None,
6669 color: None,6810 color: None,
6811+ transform: None,
6670 fit: FitPolicy::Fit,6812 fit: FitPolicy::Fit,
6671 speed: Speed::NORMAL,6813 speed: Speed::NORMAL,
6672 };6814 };
@@ -6775,6 +6917,7 @@ mod tests {
6775 two(vec![c], vec![c]),6917 two(vec![c], vec![c]),
6776 Vec::new(),6918 Vec::new(),
6777 Vec::new(),6919 Vec::new(),
6920+ Vec::new(),
6778 )6921 )
6779 .expect("valid parts")6922 .expect("valid parts")
6780 };6923 };
@@ -6913,9 +7056,9 @@ mod tests {
6913 // A saved-and-loaded empty timeline is a project like any other, and it7056 // A saved-and-loaded empty timeline is a project like any other, and it
6914 // still names the file its frame rate came from.7057 // still names the file its frame rate came from.
6915 assert!(p.lift(Lane::V1, 0));7058 assert!(p.lift(Lane::V1, 0));
6916- let (sources, lanes, eq, color) = p.without_orphan_sources();7059+ let (sources, lanes, eq, color, _transform) = p.without_orphan_sources();
6917 assert_eq!(sources.len(), 1, "source 0 survives an emptied timeline");7060 assert_eq!(sources.len(), 1, "source 0 survives an emptied timeline");
6918- let back = Project::from_parts(sources, lanes, eq, color).expect("an empty project loads");7061+ let back = Project::from_parts(sources, lanes, eq, color, Vec::new()).expect("an empty project loads");
6919 assert_eq!(back.timeline_frames(), 0);7062 assert_eq!(back.timeline_frames(), 0);
6920 assert_eq!(back.lanes().len(), 2, "and it kept its lanes");7063 assert_eq!(back.lanes().len(), 2, "and it kept its lanes");
6921 }7064 }
@@ -7089,7 +7232,7 @@ mod tests {
7089 (LaneKind::Video, vec![clip(0, 0, 3, 0), clip(10, 3, 6, 0)]),7232 (LaneKind::Video, vec![clip(0, 0, 3, 0), clip(10, 3, 6, 0)]),
7090 (LaneKind::Audio, vec![clip(0, 0, 3, 0)]),7233 (LaneKind::Audio, vec![clip(0, 0, 3, 0)]),
7091 ];7234 ];
7092- let mut p = Project::from_parts(sources, lanes, vec![], vec![]).expect("valid parts");7235+ let mut p = Project::from_parts(sources, lanes, vec![], vec![], Vec::new()).expect("valid parts");
7093 let before = shape(&p);7236 let before = shape(&p);
7094 7237
7095 // Into the gap, exactly where it was let go -- nothing else moves.7238 // Into the gap, exactly where it was let go -- nothing else moves.
@@ -7652,7 +7795,7 @@ mod tests {
7652 // Import a second file, undo it: source 1 is now an orphan.7795 // Import a second file, undo it: source 1 is now an orphan.
7653 let mut p = two_sources();7796 let mut p = two_sources();
7654 assert!(p.undo());7797 assert!(p.undo());
7655- let (sources, lanes, eq, color) = p.without_orphan_sources();7798+ let (sources, lanes, eq, color, _transform) = p.without_orphan_sources();
7656 assert_eq!(sources, vec![Source::new(FILE, 0)], "the orphan is gone");7799 assert_eq!(sources, vec![Source::new(FILE, 0)], "the orphan is gone");
7657 assert!(eq.is_empty(), "and a project with no equalizer writes none");7800 assert!(eq.is_empty(), "and a project with no equalizer writes none");
7658 assert!(color.is_empty(), "nor a colour it never graded with");7801 assert!(color.is_empty(), "nor a colour it never graded with");
@@ -7668,7 +7811,7 @@ mod tests {
7668 assert_eq!(p.import(FILE2, 0), 1);7811 assert_eq!(p.import(FILE2, 0), 1);
7669 assert_eq!(p.import("/nonexistent/c.mp4", 0), 2);7812 assert_eq!(p.import("/nonexistent/c.mp4", 0), 2);
7670 assert!(p.append_clip(2, 4));7813 assert!(p.append_clip(2, 4));
7671- let (sources, lanes, eq, color) = p.without_orphan_sources();7814+ let (sources, lanes, eq, color, _transform) = p.without_orphan_sources();
7672 assert_eq!(7815 assert_eq!(
7673 sources,7816 sources,
7674 vec![Source::new(FILE, 0), Source::new("/nonexistent/c.mp4", 0)]7817 vec![Source::new(FILE, 0), Source::new("/nonexistent/c.mp4", 0)]
@@ -7678,7 +7821,7 @@ mod tests {
7678 [0, 1]7821 [0, 1]
7679 );7822 );
7680 // ...and what comes out is loadable, with the same timeline.7823 // ...and what comes out is loadable, with the same timeline.
7681- let reloaded = Project::from_parts(sources, lanes, eq, color).expect("from_parts");7824+ let reloaded = Project::from_parts(sources, lanes, eq, color, Vec::new()).expect("from_parts");
7682 assert_eq!(reloaded.timeline_frames(), p.timeline_frames());7825 assert_eq!(reloaded.timeline_frames(), p.timeline_frames());
7683 assert_eq!(reloaded.sources().len(), 2);7826 assert_eq!(reloaded.sources().len(), 2);
7684 }7827 }
@@ -7729,8 +7872,8 @@ mod tests {
7729 );7872 );
7730 // What is left is a project that still loads, which is the whole point7873 // What is left is a project that still loads, which is the whole point
7731 // of renumbering rather than leaving a hole.7874 // of renumbering rather than leaving a hole.
7732- let (sources, lanes, eq, color) = p.without_orphan_sources();7875+ let (sources, lanes, eq, color, _transform) = p.without_orphan_sources();
7733- Project::from_parts(sources, lanes, eq, color).expect("from_parts");7876+ Project::from_parts(sources, lanes, eq, color, Vec::new()).expect("from_parts");
7734 }7877 }
7735 7878
7736 /// The two edges of a removal: it retires the undo stack (the corner-cut on7879 /// The two edges of a removal: it retires the undo stack (the corner-cut on
@@ -7836,7 +7979,7 @@ mod tests {
7836 assert!(p.undo(), "back to the first setting");7979 assert!(p.undo(), "back to the first setting");
7837 assert_eq!(p.eq_of(Lane::V1, 0), Some(&band_at(1)));7980 assert_eq!(p.eq_of(Lane::V1, 0), Some(&band_at(1)));
7838 7981
7839- let (_, lanes, eq, _) = p.without_orphan_sources();7982+ let (_, lanes, eq, _, _) = p.without_orphan_sources();
7840 assert_eq!(eq, vec![band_at(1)], "what nothing plays is not written");7983 assert_eq!(eq, vec![band_at(1)], "what nothing plays is not written");
7841 assert_eq!(lanes[0].1[0].eq, Some(0), "and the survivor renumbers");7984 assert_eq!(lanes[0].1[0].eq, Some(0), "and the survivor renumbers");
7842 assert_eq!(lanes[0].1[1].eq, None);7985 assert_eq!(lanes[0].1[1].eq, None);
@@ -7844,7 +7987,7 @@ mod tests {
7844 // One curve on three clips is one entry: settings that are equal share.7987 // One curve on three clips is one entry: settings that are equal share.
7845 assert!(p.set_eq(Lane::V1, 1, Some(band_at(1))));7988 assert!(p.set_eq(Lane::V1, 1, Some(band_at(1))));
7846 assert!(p.set_eq(Lane::A1, 2, Some(band_at(1))));7989 assert!(p.set_eq(Lane::A1, 2, Some(band_at(1))));
7847- let (_, lanes, eq, _) = p.without_orphan_sources();7990+ let (_, lanes, eq, _, _) = p.without_orphan_sources();
7848 assert_eq!(eq.len(), 1, "equal settings share their entry");7991 assert_eq!(eq.len(), 1, "equal settings share their entry");
7849 assert_eq!(lanes[1].1[2].eq, Some(0));7992 assert_eq!(lanes[1].1[2].eq, Some(0));
7850 reloads(&p, "an equalizer that outlived an undo");7993 reloads(&p, "an equalizer that outlived an undo");
@@ -7969,7 +8112,7 @@ mod tests {
7969 assert!(p.undo(), "back to the first grade");8112 assert!(p.undo(), "back to the first grade");
7970 assert_eq!(p.color_of(Lane::V1, 0), Some(&grade_at(1)));8113 assert_eq!(p.color_of(Lane::V1, 0), Some(&grade_at(1)));
7971 8114
7972- let (_, lanes, _, color) = p.without_orphan_sources();8115+ let (_, lanes, _, color, _) = p.without_orphan_sources();
7973 assert_eq!(8116 assert_eq!(
7974 color,8117 color,
7975 vec![grade_at(1)],8118 vec![grade_at(1)],
@@ -7981,36 +8124,157 @@ mod tests {
7981 // One grade on three clips is one entry: settings that are equal share.8124 // One grade on three clips is one entry: settings that are equal share.
7982 assert!(p.set_color(Lane::V1, 1, Some(grade_at(1))));8125 assert!(p.set_color(Lane::V1, 1, Some(grade_at(1))));
7983 assert!(p.set_color(Lane::A1, 2, Some(grade_at(1))));8126 assert!(p.set_color(Lane::A1, 2, Some(grade_at(1))));
7984- let (_, lanes, _, color) = p.without_orphan_sources();8127+ let (_, lanes, _, color, _) = p.without_orphan_sources();
7985 assert_eq!(color.len(), 1, "equal grades share their entry");8128 assert_eq!(color.len(), 1, "equal grades share their entry");
7986 assert_eq!(lanes[1].1[2].color, Some(0));8129 assert_eq!(lanes[1].1[2].color, Some(0));
7987 reloads(&p, "a colour that outlived an undo");8130 reloads(&p, "a colour that outlived an undo");
7988 8131
7989 // An equalizer and a grade on one clip are two independent tables.8132 // An equalizer and a grade on one clip are two independent tables.
7990 assert!(p.set_eq(Lane::V1, 0, Some(band_at(3))));8133 assert!(p.set_eq(Lane::V1, 0, Some(band_at(3))));
7991- let (_, lanes, eq, color) = p.without_orphan_sources();8134+ let (_, lanes, eq, color, _) = p.without_orphan_sources();
7992 assert_eq!((eq.len(), color.len()), (1, 1));8135 assert_eq!((eq.len(), color.len()), (1, 1));
7993 assert_eq!((lanes[0].1[0].eq, lanes[0].1[0].color), (Some(0), Some(0)));8136 assert_eq!((lanes[0].1[0].eq, lanes[0].1[0].color), (Some(0), Some(0)));
7994 }8137 }
7995 8138
8139+ /// [`a_colour_follows_the_clip_through_split_copy_and_undo`]'s twin: a
8140+ /// placement is the clip's, through every edit that copies one.
8141+ #[test]
8142+ fn a_transform_follows_the_clip_through_split_copy_and_undo() {
8143+ let mut p = three();
8144+ assert!(
8145+ p.transform_of(Lane::V1, 0).is_none(),
8146+ "a fresh clip is untransformed"
8147+ );
8148+ assert!(p.set_transform(Lane::V1, 0, Some(transform_at(2))));
8149+ assert_eq!(p.transform_of(Lane::V1, 0), Some(&transform_at(2)));
8150+ assert!(
8151+ p.transform_of(Lane::A1, 0).is_none(),
8152+ "one clip, not the lane below"
8153+ );
8154+ assert!(
8155+ p.color_of(Lane::V1, 0).is_none(),
8156+ "and a placement is not a grade"
8157+ );
8158+
8159+ // Cutting a transformed clip must not transform half of it: both
8160+ // halves inherit.
8161+ assert!(p.split(1));
8162+ assert_eq!(p.transform_of(Lane::V1, 0), Some(&transform_at(2)));
8163+ assert_eq!(p.transform_of(Lane::V1, 1), Some(&transform_at(2)));
8164+ assert!(
8165+ p.transform_of(Lane::V1, 2).is_none(),
8166+ "the clip after it is untransformed"
8167+ );
8168+
8169+ // A clipboard copy carries it -- onto another lane, at that.
8170+ let copied = p.lane(Lane::V1)[1];
8171+ assert!(p.place(Lane::A1, 20, copied));
8172+ assert_eq!(p.transform_of(Lane::A1, 4), Some(&transform_at(2)));
8173+ assert!(p.undo());
8174+ assert_eq!(p.lane(Lane::A1).len(), 4, "the placement came back off");
8175+
8176+ // ...and a change to one is one undo step, in both directions.
8177+ assert!(p.set_transform(Lane::V1, 0, Some(transform_at(5))));
8178+ assert_eq!(p.transform_of(Lane::V1, 0), Some(&transform_at(5)));
8179+ assert!(p.undo());
8180+ assert_eq!(p.transform_of(Lane::V1, 0), Some(&transform_at(2)));
8181+ assert!(
8182+ p.set_transform(Lane::V1, 0, None),
8183+ "and taking it off is an edit"
8184+ );
8185+ assert!(p.transform_of(Lane::V1, 0).is_none());
8186+ assert!(p.undo());
8187+ assert_eq!(p.transform_of(Lane::V1, 0), Some(&transform_at(2)));
8188+
8189+ // Two refusals, neither of which costs an undo step.
8190+ let nan = TransformParams {
8191+ scale: f32::NAN,
8192+ ..transform_at(1)
8193+ };
8194+ assert!(
8195+ !p.set_transform(Lane::V1, 99, Some(transform_at(1))),
8196+ "no clip there"
8197+ );
8198+ assert!(
8199+ !p.set_transform(Lane::V1, 0, Some(nan)),
8200+ "not a finite value"
8201+ );
8202+ assert_eq!(p.transform_of(Lane::V1, 0), Some(&transform_at(2)));
8203+ assert!(p.undo());
8204+ assert_eq!(
8205+ p.lane(Lane::V1).len(),
8206+ 3,
8207+ "one step back is before the split"
8208+ );
8209+ assert!(p.undo());
8210+ assert!(
8211+ p.transform_of(Lane::V1, 0).is_none(),
8212+ "and the next is before the placement: the refusals pushed none"
8213+ );
8214+ }
8215+
8216+ /// The transform table is append-only within a session, exactly as the eq
8217+ /// and colour ones are -- and a save is where an undone placement goes.
8218+ #[test]
8219+ fn an_undone_transform_is_pruned_when_the_project_is_saved() {
8220+ let mut p = three();
8221+ assert!(p.set_transform(Lane::V1, 0, Some(transform_at(1))));
8222+ assert!(p.set_transform(Lane::V1, 0, Some(transform_at(2))));
8223+ assert!(p.undo(), "back to the first placement");
8224+ assert_eq!(p.transform_of(Lane::V1, 0), Some(&transform_at(1)));
8225+
8226+ let (_, lanes, _, _, transform) = p.without_orphan_sources();
8227+ assert_eq!(
8228+ transform,
8229+ vec![transform_at(1)],
8230+ "what nothing plays is not written"
8231+ );
8232+ assert_eq!(
8233+ lanes[0].1[0].transform,
8234+ Some(0),
8235+ "and the survivor renumbers"
8236+ );
8237+ assert_eq!(lanes[0].1[1].transform, None);
8238+
8239+ // One placement on three clips is one entry: settings that are equal
8240+ // share.
8241+ assert!(p.set_transform(Lane::V1, 1, Some(transform_at(1))));
8242+ assert!(p.set_transform(Lane::A1, 2, Some(transform_at(1))));
8243+ let (_, lanes, _, _, transform) = p.without_orphan_sources();
8244+ assert_eq!(transform.len(), 1, "equal placements share their entry");
8245+ assert_eq!(lanes[1].1[2].transform, Some(0));
8246+ reloads(&p, "a transform that outlived an undo");
8247+
8248+ // A grade and a placement on one clip are two independent tables.
8249+ assert!(p.set_color(Lane::V1, 0, Some(grade_at(3))));
8250+ let (_, lanes, _, color, transform) = p.without_orphan_sources();
8251+ assert_eq!((color.len(), transform.len()), (1, 1));
8252+ assert_eq!(
8253+ (lanes[0].1[0].color, lanes[0].1[0].transform),
8254+ (Some(0), Some(0))
8255+ );
8256+ }
8257+
7996 /// Not a claim about correctness but about cost: a clip is copied on every8258 /// Not a claim about correctness but about cost: a clip is copied on every
7997 /// paste, every undo snapshot and every lane clone, so its size is worth8259 /// paste, every undo snapshot and every lane clone, so its size is worth
7998 /// knowing. The eq index fit the padding a `Copy` clip already had; the8260 /// knowing. The eq index fit the padding a `Copy` clip already had; the
7999- /// colour one did not, and the struct grew a word.8261+ /// colour one did not, and the struct grew a word. The transform index is
8262+ /// a third `Option<u16>`, and it fits the padding the fit policy and the
8263+ /// transition byte already left behind, so the struct did not grow again.
8000 #[test]8264 #[test]
8001 fn a_clip_is_still_a_small_copy() {8265 fn a_clip_is_still_a_small_copy() {
8002 assert_eq!(8266 assert_eq!(
8003 std::mem::size_of::<Clip>(),8267 std::mem::size_of::<Clip>(),
8004 56,8268 56,
8005- "Clip changed size -- 32 before the colour index, 40 before the fades, 48 after, 56 with the transition"8269+ "Clip changed size -- 32 before the colour index, 40 before the fades, 48 after, 56 with the transition, still 56 with the transform index"
8006 );8270 );
8007 }8271 }
8008 8272
8009 #[test]8273 #[test]
8010 fn from_parts_has_no_history_and_checks_the_invariants() {8274 fn from_parts_has_no_history_and_checks_the_invariants() {
8011- let (sources, lanes, eq, color) = three().without_orphan_sources();8275+ let (sources, lanes, eq, color, _transform) = three().without_orphan_sources();
8012 let (video, audio) = (lanes[0].1.clone(), lanes[1].1.clone());8276 let (video, audio) = (lanes[0].1.clone(), lanes[1].1.clone());
8013- let mut p = Project::from_parts(sources.clone(), lanes.clone(), eq.clone(), color.clone())8277+ let mut p = Project::from_parts(sources.clone(), lanes.clone(), eq.clone(), color.clone(), Vec::new())
8014 .expect("valid parts");8278 .expect("valid parts");
8015 assert_eq!(p.clips(), three().clips());8279 assert_eq!(p.clips(), three().clips());
8016 assert!(!p.undo(), "a loaded project has nothing to undo");8280 assert!(!p.undo(), "a loaded project has nothing to undo");
@@ -8025,6 +8289,7 @@ mod tests {
8025 two(video.clone(), Vec::new()),8289 two(video.clone(), Vec::new()),
8026 Vec::new(),8290 Vec::new(),
8027 Vec::new(),8291 Vec::new(),
8292+ Vec::new(),
8028 )8293 )
8029 .is_ok()8294 .is_ok()
8030 );8295 );
@@ -8034,10 +8299,11 @@ mod tests {
8034 two(Vec::new(), Vec::new()),8299 two(Vec::new(), Vec::new()),
8035 Vec::new(),8300 Vec::new(),
8036 Vec::new(),8301 Vec::new(),
8302+ Vec::new(),
8037 )8303 )
8038 .is_ok()8304 .is_ok()
8039 );8305 );
8040- assert!(Project::from_parts(sources.clone(), Vec::new(), Vec::new(), Vec::new()).is_err());8306+ assert!(Project::from_parts(sources.clone(), Vec::new(), Vec::new(), Vec::new(), Vec::new()).is_err());
8041 let bad: [Vec<Clip>; 5] = [8307 let bad: [Vec<Clip>; 5] = [
8042 vec![clip(0, 0, 3, 1)], // source that is not there8308 vec![clip(0, 0, 3, 1)], // source that is not there
8043 vec![clip(0, 3, 3, 0)], // empty clip8309 vec![clip(0, 3, 3, 0)], // empty clip
@@ -8052,6 +8318,7 @@ mod tests {
8052 two(clips.clone(), Vec::new()),8318 two(clips.clone(), Vec::new()),
8053 Vec::new(),8319 Vec::new(),
8054 Vec::new(),8320 Vec::new(),
8321+ Vec::new(),
8055 )8322 )
8056 .is_err(),8323 .is_err(),
8057 "{clips:?}"8324 "{clips:?}"
@@ -8062,6 +8329,7 @@ mod tests {
8062 two(video.clone(), clips.clone()),8329 two(video.clone(), clips.clone()),
8063 Vec::new(),8330 Vec::new(),
8064 Vec::new(),8331 Vec::new(),
8332+ Vec::new(),
8065 )8333 )
8066 .is_err()8334 .is_err()
8067 );8335 );
@@ -8076,6 +8344,7 @@ mod tests {
8076 ],8344 ],
8077 Vec::new(),8345 Vec::new(),
8078 Vec::new(),8346 Vec::new(),
8347+ Vec::new(),
8079 )8348 )
8080 .is_err()8349 .is_err()
8081 );8350 );
@@ -8097,6 +8366,7 @@ mod tests {
8097 two(eqd(0), Vec::new()),8366 two(eqd(0), Vec::new()),
8098 Vec::new(),8367 Vec::new(),
8099 Vec::new(),8368 Vec::new(),
8369+ Vec::new(),
8100 )8370 )
8101 .is_err()8371 .is_err()
8102 );8372 );
@@ -8108,6 +8378,7 @@ mod tests {
8108 two(eqd(0), Vec::new()),8378 two(eqd(0), Vec::new()),
8109 vec![nan],8379 vec![nan],
8110 Vec::new(),8380 Vec::new(),
8381+ Vec::new(),
8111 )8382 )
8112 .is_err()8383 .is_err()
8113 );8384 );
@@ -8116,6 +8387,7 @@ mod tests {
8116 two(eqd(0), Vec::new()),8387 two(eqd(0), Vec::new()),
8117 vec![band_at(1)],8388 vec![band_at(1)],
8118 Vec::new(),8389 Vec::new(),
8390+ Vec::new(),
8119 )8391 )
8120 .expect("an eq the table holds");8392 .expect("an eq the table holds");
8121 assert_eq!(loaded.eq_of(Lane::V1, 0), Some(&band_at(1)));8393 assert_eq!(loaded.eq_of(Lane::V1, 0), Some(&band_at(1)));
@@ -8138,6 +8410,7 @@ mod tests {
8138 two(graded(0), Vec::new()),8410 two(graded(0), Vec::new()),
8139 Vec::new(),8411 Vec::new(),
8140 Vec::new(),8412 Vec::new(),
8413+ Vec::new(),
8141 )8414 )
8142 .is_err(),8415 .is_err(),
8143 "a colour index no entry answers"8416 "a colour index no entry answers"
@@ -8151,6 +8424,7 @@ mod tests {
8151 tint: f32::NAN,8424 tint: f32::NAN,
8152 ..grade_at(1)8425 ..grade_at(1)
8153 }],8426 }],
8427+ Vec::new(),
8154 )8428 )
8155 .is_err(),8429 .is_err(),
8156 "a value the file format could not have written"8430 "a value the file format could not have written"
@@ -8160,12 +8434,13 @@ mod tests {
8160 two(graded(0), Vec::new()),8434 two(graded(0), Vec::new()),
8161 Vec::new(),8435 Vec::new(),
8162 vec![grade_at(1)],8436 vec![grade_at(1)],
8437+ Vec::new(),
8163 )8438 )
8164 .expect("a colour the table holds");8439 .expect("a colour the table holds");
8165 assert_eq!(loaded.color_of(Lane::V1, 0), Some(&grade_at(1)));8440 assert_eq!(loaded.color_of(Lane::V1, 0), Some(&grade_at(1)));
8166 8441
8167 // Group ids survive a load, and the next split gets a fresh one.8442 // Group ids survive a load, and the next split gets a fresh one.
8168- let mut p = Project::from_parts(sources, lanes, eq, color).expect("valid parts");8443+ let mut p = Project::from_parts(sources, lanes, eq, color, Vec::new()).expect("valid parts");
8169 assert!(p.split(4));8444 assert!(p.split(4));
8170 assert!(p.clips().iter().all(|c| c.link.is_some()));8445 assert!(p.clips().iter().all(|c| c.link.is_some()));
8171 }8446 }
@@ -8194,13 +8469,14 @@ mod tests {
8194 link: Some(link),8469 link: Some(link),
8195 eq: None,8470 eq: None,
8196 color: None,8471 color: None,
8472+ transform: None,
8197 fit: FitPolicy::default(),8473 fit: FitPolicy::default(),
8198 speed: Speed::NORMAL,8474 speed: Speed::NORMAL,
8199 };8475 };
8200 8476
8201 // The door: a doubled id inside one lane, refused by name.8477 // The door: a doubled id inside one lane, refused by name.
8202 let err = |video: Vec<Clip>, audio: Vec<Clip>| {8478 let err = |video: Vec<Clip>, audio: Vec<Clip>| {
8203- Project::from_parts(sources.clone(), two(video, audio), Vec::new(), Vec::new())8479+ Project::from_parts(sources.clone(), two(video, audio), Vec::new(), Vec::new(), Vec::new())
8204 .expect_err("refused")8480 .expect_err("refused")
8205 .to_string()8481 .to_string()
8206 };8482 };
@@ -8235,14 +8511,15 @@ mod tests {
8235 two(vec![linked(0, 0, 5, 2)], vec![linked(0, 0, 3, 2)]),8511 two(vec![linked(0, 0, 5, 2)], vec![linked(0, 0, 3, 2)]),
8236 Vec::new(),8512 Vec::new(),
8237 Vec::new(),8513 Vec::new(),
8514+ Vec::new(),
8238 );8515 );
8239 assert!(apart.is_ok(), "offsets within one group load: {apart:?}");8516 assert!(apart.is_ok(), "offsets within one group load: {apart:?}");
8240 // A one-sided link is *not* an error: it is what a lift leaves behind.8517 // A one-sided link is *not* an error: it is what a lift leaves behind.
8241 let mut p = Project::single(FILE, 9);8518 let mut p = Project::single(FILE, 9);
8242 assert!(p.lift(Lane::A1, 0));8519 assert!(p.lift(Lane::A1, 0));
8243- let (sources, lanes, eq, color) = p.clone().without_orphan_sources();8520+ let (sources, lanes, eq, color, _transform) = p.clone().without_orphan_sources();
8244 assert!(8521 assert!(
8245- Project::from_parts(sources, lanes, eq, color).is_ok(),8522+ Project::from_parts(sources, lanes, eq, color, Vec::new()).is_ok(),
8246 "a lifted lane's project has to load again"8523 "a lifted lane's project has to load again"
8247 );8524 );
8248 8525
@@ -8637,8 +8914,8 @@ mod tests {
8637 /// handed back to the constructor a load goes through -- every lane of them,8914 /// handed back to the constructor a load goes through -- every lane of them,
8638 /// and the reloaded timeline has to be the same lanes in the same order.8915 /// and the reloaded timeline has to be the same lanes in the same order.
8639 fn reloads(p: &Project, what: &str) {8916 fn reloads(p: &Project, what: &str) {
8640- let (sources, lanes, eq, color) = p.clone().without_orphan_sources();8917+ let (sources, lanes, eq, color, transform) = p.clone().without_orphan_sources();
8641- match Project::from_parts(sources, lanes, eq, color) {8918+ match Project::from_parts(sources, lanes, eq, color, transform) {
8642 Err(e) => panic!("{what}: saved but would not load: {e}\n{:?}", p.lanes),8919 Err(e) => panic!("{what}: saved but would not load: {e}\n{:?}", p.lanes),
8643 Ok(back) => {8920 Ok(back) => {
8644 assert_eq!(back.lanes(), p.lanes(), "{what}: the lane list changed");8921 assert_eq!(back.lanes(), p.lanes(), "{what}: the lane list changed");
@@ -8674,6 +8951,22 @@ mod tests {
8674 .collect()8951 .collect()
8675 };8952 };
8676 assert_eq!(colors(&back), colors(p), "{what}: the colours changed");8953 assert_eq!(colors(&back), colors(p), "{what}: the colours changed");
8954+ // ...and the transform table, by the same claim again.
8955+ let transforms = |p: &Project| -> Vec<Vec<Option<TransformParams>>> {
8956+ p.lanes()
8957+ .into_iter()
8958+ .map(|l| {
8959+ (0..p.lane(l).len())
8960+ .map(|i| p.transform_of(l, i).copied())
8961+ .collect()
8962+ })
8963+ .collect()
8964+ };
8965+ assert_eq!(
8966+ transforms(&back),
8967+ transforms(p),
8968+ "{what}: the transforms changed"
8969+ );
8677 }8970 }
8678 }8971 }
8679 }8972 }
@@ -8888,12 +9181,12 @@ mod tests {
8888 invariants_hold(&p, "V2 over V1");9181 invariants_hold(&p, "V2 over V1");
8889 9182
8890 // A save writes that order and a load takes it back.9183 // A save writes that order and a load takes it back.
8891- let (sources, lanes, eq, color) = p.without_orphan_sources();9184+ let (sources, lanes, eq, color, _transform) = p.without_orphan_sources();
8892 assert_eq!(9185 assert_eq!(
8893 lanes.iter().map(|(k, _)| *k).collect::<Vec<_>>(),9186 lanes.iter().map(|(k, _)| *k).collect::<Vec<_>>(),
8894 [LaneKind::Video, LaneKind::Video, LaneKind::Audio]9187 [LaneKind::Video, LaneKind::Video, LaneKind::Audio]
8895 );9188 );
8896- let back = Project::from_parts(sources, lanes, eq, color).expect("three lanes load");9189+ let back = Project::from_parts(sources, lanes, eq, color, Vec::new()).expect("three lanes load");
8897 assert_eq!(back.lanes(), p.lanes());9190 assert_eq!(back.lanes(), p.lanes());
8898 assert_eq!(shape(&back), shape(&p), "the same lane is still on top");9191 assert_eq!(shape(&back), shape(&p), "the same lane is still on top");
8899 9192
@@ -8974,6 +9267,7 @@ mod tests {
8974 link: Some(link),9267 link: Some(link),
8975 eq: None,9268 eq: None,
8976 color: None,9269 color: None,
9270+ transform: None,
8977 fit: FitPolicy::default(),9271 fit: FitPolicy::default(),
8978 speed: Speed::NORMAL,9272 speed: Speed::NORMAL,
8979 };9273 };
@@ -9024,7 +9318,7 @@ mod tests {
9024 let v2 = p.add_lane(LaneKind::Video);9318 let v2 = p.add_lane(LaneKind::Video);
9025 assert!(p.place(v2, 4, clip(0, 20, 32, 0)));9319 assert!(p.place(v2, 4, clip(0, 20, 32, 0)));
9026 let a2 = p.add_lane(LaneKind::Audio);9320 let a2 = p.add_lane(LaneKind::Audio);
9027- let (sources, lanes, eq, color) = p.without_orphan_sources();9321+ let (sources, lanes, eq, color, _transform) = p.without_orphan_sources();
9028 assert_eq!(9322 assert_eq!(
9029 lanes.iter().map(|(k, _)| *k).collect::<Vec<_>>(),9323 lanes.iter().map(|(k, _)| *k).collect::<Vec<_>>(),
9030 [9324 [
@@ -9038,7 +9332,7 @@ mod tests {
9038 assert_eq!(lanes[2].1, p.lane(v2), "V2's clips are written");9332 assert_eq!(lanes[2].1, p.lane(v2), "V2's clips are written");
9039 assert!(lanes[3].1.is_empty(), "and the empty A2 is still a lane");9333 assert!(lanes[3].1.is_empty(), "and the empty A2 is still a lane");
9040 // ...and all four load again as the same four.9334 // ...and all four load again as the same four.
9041- let back = Project::from_parts(sources, lanes, eq, color).expect("four lanes load");9335+ let back = Project::from_parts(sources, lanes, eq, color, Vec::new()).expect("four lanes load");
9042 assert_eq!(back.lanes(), p.lanes());9336 assert_eq!(back.lanes(), p.lanes());
9043 assert_eq!(back.lane(a2), p.lane(a2));9337 assert_eq!(back.lane(a2), p.lane(a2));
9044 9338
@@ -9131,7 +9425,7 @@ mod tests {
9131 (LaneKind::Video, vec![clip(10, 5, 15, 1)]),9425 (LaneKind::Video, vec![clip(10, 5, 15, 1)]),
9132 (LaneKind::Audio, vec![clip(0, 0, 30, 0)]),9426 (LaneKind::Audio, vec![clip(0, 0, 30, 0)]),
9133 ];9427 ];
9134- let p = Project::from_parts(sources, lanes, vec![], vec![]).expect("valid parts");9428+ let p = Project::from_parts(sources, lanes, vec![], vec![], Vec::new()).expect("valid parts");
9135 assert_eq!(9429 assert_eq!(
9136 p.composite_spans_from(0),9430 p.composite_spans_from(0),
9137 vec![9431 vec![
@@ -9176,7 +9470,7 @@ mod tests {
9176 (LaneKind::Video, vec![clip(10, 0, 10, 1)]),9470 (LaneKind::Video, vec![clip(10, 0, 10, 1)]),
9177 (LaneKind::Audio, vec![clip(0, 0, 30, 0)]),9471 (LaneKind::Audio, vec![clip(0, 0, 30, 0)]),
9178 ];9472 ];
9179- let p = Project::from_parts(sources, holed, vec![], vec![]).expect("valid parts");9473+ let p = Project::from_parts(sources, holed, vec![], vec![], Vec::new()).expect("valid parts");
9180 assert_eq!(9474 assert_eq!(
9181 p.composite_spans_from(0),9475 p.composite_spans_from(0),
9182 vec![9476 vec![
@@ -9224,7 +9518,7 @@ mod tests {
9224 (LaneKind::Audio, vec![clip(15, 0, 15, 1)]),9518 (LaneKind::Audio, vec![clip(15, 0, 15, 1)]),
9225 (LaneKind::Audio, Vec::new()),9519 (LaneKind::Audio, Vec::new()),
9226 ];9520 ];
9227- let p = Project::from_parts(sources, lanes, vec![], vec![]).expect("valid parts");9521+ let p = Project::from_parts(sources, lanes, vec![], vec![], Vec::new()).expect("valid parts");
9228 let lists = p.audio_segments_from(0, FPS);9522 let lists = p.audio_segments_from(0, FPS);
9229 assert_eq!(lists.len(), 2, "the empty lane is not mixed in");9523 assert_eq!(lists.len(), 2, "the empty lane is not mixed in");
9230 assert_eq!(lists[0], p.segments_from(0, FPS), "A1 is unchanged");9524 assert_eq!(lists[0], p.segments_from(0, FPS), "A1 is unchanged");
@@ -9241,6 +9535,7 @@ mod tests {
9241 ],9535 ],
9242 vec![],9536 vec![],
9243 vec![],9537 vec![],
9538+ Vec::new(),
9244 )9539 )
9245 .expect("valid parts");9540 .expect("valid parts");
9246 assert_eq!(p.audio_segments_from(0, FPS), vec![vec![(None, 0.0, 1.0)]]);9541 assert_eq!(p.audio_segments_from(0, FPS), vec![vec![(None, 0.0, 1.0)]]);
crates/engine/src/proxy.rsmodified+2 -0
@@ -497,6 +497,7 @@ fn started(source: &Path, only_if: fn(&VideoMeta) -> bool) -> crate::Result<Opti
497 link: None,497 link: None,
498 eq: None,498 eq: None,
499 color: None,499 color: None,
500+ transform: None,
500 fit: FitPolicy::default(),501 fit: FitPolicy::default(),
501 speed: Speed::NORMAL,502 speed: Speed::NORMAL,
502 };503 };
@@ -505,6 +506,7 @@ fn started(source: &Path, only_if: fn(&VideoMeta) -> bool) -> crate::Result<Opti
505 vec![(LaneKind::Video, vec![clip])],506 vec![(LaneKind::Video, vec![clip])],
506 Vec::new(),507 Vec::new(),
507 Vec::new(),508 Vec::new(),
509+ Vec::new(),
508 )?;510 )?;
509 let bitrate =511 let bitrate =
510 (f64::from(width) * f64::from(height) * meta.frame_rate * BITS_PER_PIXEL) as u64;512 (f64::from(width) * f64::from(height) * meta.frame_rate * BITS_PER_PIXEL) as u64;
crates/engine/src/scale.rsmodified+365 -0
@@ -26,6 +26,8 @@
26 //! chroma-sample bias that no eye finds and that a siting-aware kernel would fix26 //! chroma-sample bias that no eye finds and that a siting-aware kernel would fix
27 //! in the same place the Lanczos upgrade goes.27 //! in the same place the Lanczos upgrade goes.
28 28
29+use crate::transform::TransformParams;
30+
29 /// Limited-range black: what an untouched canvas pixel is.31 /// Limited-range black: what an untouched canvas pixel is.
30 pub const BLACK_Y: u8 = 16;32 pub const BLACK_Y: u8 = 16;
31 /// Neutral chroma: 128 in both planes.33 /// Neutral chroma: 128 in both planes.
@@ -330,6 +332,130 @@ pub fn compose_i420(
330 }332 }
331 }333 }
332 334
335+/// The source rect [`TransformParams`]'s crop fractions cut out of a `src_w` x
336+/// `src_h` picture, chroma-grid aligned exactly as [`fit_rect`]'s rects are.
337+/// Fractions are clamped to `0.0..=0.5` a side, so opposing crops can never
338+/// meet or cross -- the smallest surviving rect is one chroma sample, for
339+/// [`align`]'s reason.
340+pub fn crop_rect(src_w: u32, src_h: u32, t: &TransformParams) -> Rect {
341+ if src_w == 0 || src_h == 0 {
342+ return Rect { x: 0, y: 0, w: 0, h: 0 };
343+ }
344+ let (cl, cr) = (t.crop_l.clamp(0.0, 0.5), t.crop_r.clamp(0.0, 0.5));
345+ let (ct, cb) = (t.crop_t.clamp(0.0, 0.5), t.crop_b.clamp(0.0, 0.5));
346+ let x0 = (f64::from(src_w) * f64::from(cl)).round() as u32;
347+ let x1 = (f64::from(src_w) * (1.0 - f64::from(cr))).round() as u32;
348+ let y0 = (f64::from(src_h) * f64::from(ct)).round() as u32;
349+ let y1 = (f64::from(src_h) * (1.0 - f64::from(cb))).round() as u32;
350+ let (x, w) = align(x0.min(src_w), x1.saturating_sub(x0), src_w);
351+ let (y, h) = align(y0.min(src_h), y1.saturating_sub(y0), src_h);
352+ Rect { x, y, w, h }
353+}
354+
355+/// `dst` -- a placement [`fit_rect`] already worked out -- moved by
356+/// [`TransformParams::pos_x`]/`pos_y` (canvas fractions, about `dst`'s own
357+/// centre) and resized by `scale` (about that same centre), clamped onto the
358+/// canvas and chroma-grid aligned like every other rect here.
359+///
360+/// corner-cut: a placement pushed partway off the canvas is clipped at the
361+/// edge (what [`compose_i420`] already does to any rect), not wrapped or
362+/// reflected -- there is no picture to draw once it is entirely off, and
363+/// [`compose_i420`] already refuses that case by returning without a write.
364+pub fn transformed_dst_rect(dst: Rect, t: &TransformParams, canvas_w: u32, canvas_h: u32) -> Rect {
365+ if dst.is_empty() || canvas_w == 0 || canvas_h == 0 {
366+ return dst;
367+ }
368+ let scale = if t.scale.is_finite() && t.scale > 0.0 {
369+ f64::from(t.scale)
370+ } else {
371+ 1.0
372+ };
373+ let new_w = ((f64::from(dst.w) * scale).round() as i64).clamp(1, i64::from(canvas_w));
374+ let new_h = ((f64::from(dst.h) * scale).round() as i64).clamp(1, i64::from(canvas_h));
375+ let pos_x = if t.pos_x.is_finite() { f64::from(t.pos_x) } else { 0.0 };
376+ let pos_y = if t.pos_y.is_finite() { f64::from(t.pos_y) } else { 0.0 };
377+ let cx = i64::from(dst.x) + i64::from(dst.w) / 2 + (f64::from(canvas_w) * pos_x).round() as i64;
378+ let cy = i64::from(dst.y) + i64::from(dst.h) / 2 + (f64::from(canvas_h) * pos_y).round() as i64;
379+ let x = (cx - new_w / 2).clamp(0, i64::from(canvas_w)) as u32;
380+ let y = (cy - new_h / 2).clamp(0, i64::from(canvas_h)) as u32;
381+ let (x, w) = align(x, new_w as u32, canvas_w);
382+ let (y, h) = align(y, new_h as u32, canvas_h);
383+ Rect { x, y, w, h }
384+}
385+
386+/// Nearest 90-degree step `degrees` renders at: `0` (0deg), `1` (90deg
387+/// clockwise), `2` (180deg) or `3` (270deg). Continuous rotation is not
388+/// rendered at all -- see the [`crate::transform`] module docs -- so this is
389+/// the one lossy step between what a project *stores* and what a frame
390+/// *shows*. Non-finite folds to `0`.
391+pub fn nearest_90_steps(degrees: f32) -> u8 {
392+ if !degrees.is_finite() {
393+ return 0;
394+ }
395+ let norm = degrees.rem_euclid(360.0);
396+ ((norm / 90.0).round() as i64).rem_euclid(4) as u8
397+}
398+
399+/// Rotates a tightly packed I420 frame by `steps` quarter turns clockwise
400+/// (`steps % 4`; see [`nearest_90_steps`]). `0` and `2` keep the frame's
401+/// shape, `1` and `3` swap it -- the chroma planes rotate the same way at
402+/// their own `(w+1)/2` x `(h+1)/2` size, which stays exact because it is
403+/// exactly the luma size's, swapped the same way.
404+pub fn rotate_i420_90s(
405+ y: &[u8],
406+ u: &[u8],
407+ v: &[u8],
408+ w: u32,
409+ h: u32,
410+ steps: u8,
411+) -> (Vec<u8>, Vec<u8>, Vec<u8>, u32, u32) {
412+ let steps = steps % 4;
413+ if steps == 0 || w == 0 || h == 0 {
414+ return (y.to_vec(), u.to_vec(), v.to_vec(), w, h);
415+ }
416+ let (cw, ch) = chroma_dims(w as usize, h as usize);
417+ let (ry, rw, rh) = rotate_plane(y, w as usize, h as usize, steps);
418+ let (ru, ..) = rotate_plane(u, cw, ch, steps);
419+ let (rv, ..) = rotate_plane(v, cw, ch, steps);
420+ (ry, ru, rv, rw as u32, rh as u32)
421+}
422+
423+/// One tightly packed plane, rotated `steps` (1..=3) quarter turns clockwise.
424+fn rotate_plane(src: &[u8], w: usize, h: usize, steps: u8) -> (Vec<u8>, usize, usize) {
425+ match steps {
426+ 1 => {
427+ let (nw, nh) = (h, w);
428+ let mut out = vec![0u8; nw * nh];
429+ for yp in 0..nh {
430+ for xp in 0..nw {
431+ out[yp * nw + xp] = src[(h - 1 - xp) * w + yp];
432+ }
433+ }
434+ (out, nw, nh)
435+ }
436+ 2 => {
437+ let mut out = vec![0u8; w * h];
438+ for yp in 0..h {
439+ for xp in 0..w {
440+ out[yp * w + xp] = src[(h - 1 - yp) * w + (w - 1 - xp)];
441+ }
442+ }
443+ (out, w, h)
444+ }
445+ 3 => {
446+ let (nw, nh) = (h, w);
447+ let mut out = vec![0u8; nw * nh];
448+ for yp in 0..nh {
449+ for xp in 0..nw {
450+ out[yp * nw + xp] = src[xp * w + (w - 1 - yp)];
451+ }
452+ }
453+ (out, nw, nh)
454+ }
455+ _ => unreachable!("steps % 4 is 1, 2 or 3 here"),
456+ }
457+}
458+
333 /// One clip's pictures placed on the project canvas: the geometry, plus the459 /// One clip's pictures placed on the project canvas: the geometry, plus the
334 /// buffers it composes into so a frame costs no allocation.460 /// buffers it composes into so a frame costs no allocation.
335 ///461 ///
@@ -485,6 +611,98 @@ impl Composer {
485 compose_i420(ky, ku, kv, w, h, pic_y, pic_u, pic_v, dst);611 compose_i420(ky, ku, kv, w, h, pic_y, pic_u, pic_v, dst);
486 (ky, ku, kv, self.width, self.height)612 (ky, ku, kv, self.width, self.height)
487 }613 }
614+
615+ /// [`place`](Self::place) with a per-clip [`TransformParams`] applied on
616+ /// top of the fit policy: the source is cropped to [`crop_rect`], rotated
617+ /// by [`rotate_i420_90s`] to [`nearest_90_steps`] of `t.rotate`, fit to the
618+ /// canvas exactly as an untransformed picture is, and the fitted
619+ /// placement is then moved/resized by [`transformed_dst_rect`].
620+ /// `t.is_identity()` takes the exact [`place`](Self::place) path.
621+ ///
622+ /// corner-cut: unlike `place`, this always allocates its crop and rotate
623+ /// buffers fresh rather than reusing `self`'s -- the grade path already
624+ /// pays the same per-frame cost for a graded clip
625+ /// ([`crate::decode::Render::frame`]'s `graded` copy), so a transformed
626+ /// clip follows that precedent instead of adding a second steady-state
627+ /// buffer budget. Upgrade path if this shows up in a measurement: give
628+ /// `Composer` its own crop/rotate scratch fields, sized once like `crop`
629+ /// and `scaled` already are.
630+ pub fn place_transformed(
631+ &mut self,
632+ y: &[u8],
633+ u: &[u8],
634+ v: &[u8],
635+ src_w: u32,
636+ src_h: u32,
637+ t: &TransformParams,
638+ ) -> (Vec<u8>, Vec<u8>, Vec<u8>, u32, u32) {
639+ if t.is_identity() {
640+ let (y, u, v, w, h) = self.place(y, u, v, src_w, src_h);
641+ return (y.to_vec(), u.to_vec(), v.to_vec(), w, h);
642+ }
643+ // A pass-through canvas still has a picture to place a transform on;
644+ // treat it as a canvas the exact size of the incoming picture, so a
645+ // transformed clip at the project's own resolution still crops,
646+ // rotates and moves instead of skipping straight through.
647+ let (canvas_w, canvas_h) = if self.width == 0 || self.height == 0 {
648+ (src_w, src_h)
649+ } else {
650+ (self.width, self.height)
651+ };
652+
653+ let crop = crop_rect(src_w, src_h, t);
654+ let mut buf = (Vec::new(), Vec::new(), Vec::new());
655+ let (cy, cu, cv) = if (crop.w, crop.h) == (src_w, src_h) {
656+ (y, u, v)
657+ } else {
658+ crop_i420(&mut buf, y, u, v, src_w as usize, src_h as usize, crop);
659+ (&buf.0[..], &buf.1[..], &buf.2[..])
660+ };
661+
662+ let steps = nearest_90_steps(t.rotate);
663+ let (ry, ru, rv, rw, rh) = rotate_i420_90s(cy, cu, cv, crop.w, crop.h, steps);
664+
665+ let (dst, src) = fit_rect(rw, rh, canvas_w, canvas_h, self.policy);
666+ let (rw_u, rh_u) = (rw as usize, rh as usize);
667+ let (fy, fu, fv) = if (src.w, src.h) == (rw, rh) {
668+ (&ry[..], &ru[..], &rv[..])
669+ } else {
670+ crop_i420(&mut buf, &ry, &ru, &rv, rw_u, rh_u, src);
671+ (&buf.0[..], &buf.1[..], &buf.2[..])
672+ };
673+
674+ let dst = transformed_dst_rect(dst, t, canvas_w, canvas_h);
675+ let (sw, sh) = (src.w as usize, src.h as usize);
676+ let (dw, dh) = (dst.w as usize, dst.h as usize);
677+ let mut scaled = (Vec::new(), Vec::new(), Vec::new());
678+ let (py, pu, pv) = if (sw, sh) == (dw, dh) {
679+ (fy, fu, fv)
680+ } else {
681+ let (ccw, cch) = chroma_dims(dw, dh);
682+ scaled.0.resize(dw * dh, 0);
683+ scaled.1.resize(ccw * cch, 0);
684+ scaled.2.resize(ccw * cch, 0);
685+ scale_i420(
686+ fy, fu, fv, sw, sh, &mut scaled.0, &mut scaled.1, &mut scaled.2, dw, dh,
687+ );
688+ (&scaled.0[..], &scaled.1[..], &scaled.2[..])
689+ };
690+
691+ let (w, h) = (canvas_w as usize, canvas_h as usize);
692+ let mut canvas = black_i420(w, h);
693+ compose_i420(
694+ &mut canvas.0,
695+ &mut canvas.1,
696+ &mut canvas.2,
697+ w,
698+ h,
699+ py,
700+ pu,
701+ pv,
702+ dst,
703+ );
704+ (canvas.0, canvas.1, canvas.2, canvas_w, canvas_h)
705+ }
488 }706 }
489 707
490 /// Per-byte lerp of two same-sized I420 frames: `out = a + (b - a) * t`, on708 /// Per-byte lerp of two same-sized I420 frames: `out = a + (b - a) * t`, on
@@ -1134,4 +1352,151 @@ mod tests {
1134 let (y1, _, _) = blend_i420((&a.0, &a.1, &a.2), (&b.0, &b.1, &b.2), 1.0);1352 let (y1, _, _) = blend_i420((&a.0, &a.1, &a.2), (&b.0, &b.1, &b.2), 1.0);
1135 assert_eq!(y1, b.0);1353 assert_eq!(y1, b.0);
1136 }1354 }
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+ }
1137 }1502 }
crates/engine/src/silence.rsmodified+1 -0
@@ -305,6 +305,7 @@ mod tests {
305 link: None,305 link: None,
306 eq: None,306 eq: None,
307 color: None,307 color: None,
308+ transform: None,
308 fit: FitPolicy::default(),309 fit: FitPolicy::default(),
309 speed,310 speed,
310 }311 }
crates/engine/src/sweep.rsmodified+1 -0
@@ -76,6 +76,7 @@ fn clip(start: u32, in_frame: u32, out_frame: u32) -> Clip {
76 link: None,76 link: None,
77 eq: None,77 eq: None,
78 color: None,78 color: None,
79+ transform: None,
79 fit: FitPolicy::Fit,80 fit: FitPolicy::Fit,
80 speed: Speed::NORMAL,81 speed: Speed::NORMAL,
81 }82 }
crates/engine/src/transform.rsadded+81 -0
@@ -0,0 +1,81 @@
1+//! Per-clip position/scale/rotate/crop, applied engine-side on the placed
2+//! picture so that playback and export land the same pixel from the same
3+//! numbers -- [`crate::color::ColorParams`]'s twin in every respect but what
4+//! it moves: a grade changes what a sample *is*, this changes where it *goes*.
5+//!
6+//! Plain data with no invariants of its own: out-of-range or non-finite
7+//! values are clamped where the geometry is built ([`crate::scale::crop_rect`],
8+//! [`crate::scale::transformed_dst_rect`]), so a deserializer can hand this
9+//! over unchecked, exactly as [`ColorParams`](crate::color::ColorParams) can.
10+
11+/// One clip's placement on the project canvas, on top of whatever
12+/// [`crate::scale::FitPolicy`] already does.
13+#[derive(Debug, Clone, Copy, PartialEq)]
14+pub struct TransformParams {
15+ /// Canvas-fraction offset from centred, positive right. `0.0` is
16+ /// identity.
17+ pub pos_x: f32,
18+ /// Canvas-fraction offset from centred, positive down. `0.0` is identity.
19+ pub pos_y: f32,
20+ /// Multiplier on the fit-policy placement size. `1.0` is identity.
21+ pub scale: f32,
22+ /// Degrees, clockwise. Rendered at the nearest 90-degree step
23+ /// ([`crate::scale::rotate_i420_90s`]); the value itself is kept exactly,
24+ /// so a UI that later grows continuous rotation loses nothing already
25+ /// saved. `0.0` is identity.
26+ pub rotate: f32,
27+ /// Fraction of the source cropped off the left, `0.0..0.5`.
28+ pub crop_l: f32,
29+ /// Fraction of the source cropped off the right, `0.0..0.5`.
30+ pub crop_r: f32,
31+ /// Fraction of the source cropped off the top, `0.0..0.5`.
32+ pub crop_t: f32,
33+ /// Fraction of the source cropped off the bottom, `0.0..0.5`.
34+ pub crop_b: f32,
35+}
36+
37+impl Default for TransformParams {
38+ fn default() -> Self {
39+ Self {
40+ pos_x: 0.0,
41+ pos_y: 0.0,
42+ scale: 1.0,
43+ rotate: 0.0,
44+ crop_l: 0.0,
45+ crop_r: 0.0,
46+ crop_t: 0.0,
47+ crop_b: 0.0,
48+ }
49+ }
50+}
51+
52+impl TransformParams {
53+ /// Whether this is the do-nothing setting. Compared exactly, for
54+ /// [`crate::color::ColorParams::is_identity`]'s reason: only a value that
55+ /// is precisely identity is allowed to skip the geometry.
56+ pub fn is_identity(&self) -> bool {
57+ self.pos_x == 0.0
58+ && self.pos_y == 0.0
59+ && self.scale == 1.0
60+ && self.rotate == 0.0
61+ && self.crop_l == 0.0
62+ && self.crop_r == 0.0
63+ && self.crop_t == 0.0
64+ && self.crop_b == 0.0
65+ }
66+}
67+
68+#[cfg(test)]
69+mod tests {
70+ use super::*;
71+
72+ #[test]
73+ fn default_is_identity() {
74+ assert!(TransformParams::default().is_identity());
75+ assert!(!TransformParams {
76+ pos_x: 0.001,
77+ ..TransformParams::default()
78+ }
79+ .is_identity());
80+ }
81+}
crates/engine/tests/audio_export.rsmodified+17 -1
@@ -73,6 +73,7 @@ fn mixed_project() -> Project {
73 color: None,73 color: None,
74 fit: FitPolicy::default(),74 fit: FitPolicy::default(),
75 speed: Speed::NORMAL,75 speed: Speed::NORMAL,
76+ transform: None,
76 };77 };
77 Project::from_parts(78 Project::from_parts(
78 vec![79 vec![
@@ -98,12 +99,14 @@ fn mixed_project() -> Project {
98 color: None,99 color: None,
99 fit: FitPolicy::default(),100 fit: FitPolicy::default(),
100 speed: Speed::NORMAL,101 speed: Speed::NORMAL,
102+ transform: None,
101 }],103 }],
102 ),104 ),
103 (LaneKind::Audio, vec![clip(0, 0), clip(60, 1)]),105 (LaneKind::Audio, vec![clip(0, 0), clip(60, 1)]),
104 ],106 ],
105 Vec::new(),107 Vec::new(),
106 Vec::new(),108 Vec::new(),
109+ Vec::new(),
107 )110 )
108 .expect("a two-source project with a hole in the audio lane")111 .expect("a two-source project with a hole in the audio lane")
109 }112 }
@@ -345,6 +348,7 @@ fn a_still_and_a_song_export_as_an_mp4_with_sound() {
345 color: None,348 color: None,
346 fit: FitPolicy::default(),349 fit: FitPolicy::default(),
347 speed: Speed::NORMAL,350 speed: Speed::NORMAL,
351+ transform: None,
348 };352 };
349 // Two seconds of each at the project's own 30 fps: a still has no length of353 // Two seconds of each at the project's own 30 fps: a still has no length of
350 // its own and the song is longer than what is placed.354 // 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() {
356 ],360 ],
357 Vec::new(),361 Vec::new(),
358 Vec::new(),362 Vec::new(),
363+ Vec::new(),
359 )364 )
360 .expect("a still under a song");365 .expect("a still under a song");
361 // The project's own picture size and rate: the still decides the one and366 // 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() {
412 color: None,417 color: None,
413 fit: FitPolicy::default(),418 fit: FitPolicy::default(),
414 speed: Speed::NORMAL,419 speed: Speed::NORMAL,
420+ transform: None,
415 };421 };
416 let four = || {422 let four = || {
417 Project::from_parts(423 Project::from_parts(
@@ -425,7 +431,8 @@ fn a_fader_is_one_tracks_own_and_the_limiter_holds_the_sum() {
425 ],431 ],
426 Vec::new(),432 Vec::new(),
427 Vec::new(),433 Vec::new(),
428- )434+ Vec::new(),
435+ )
429 .expect("one second on four audio tracks")436 .expect("one second on four audio tracks")
430 };437 };
431 let write = |project: Project, name: &str| {438 let write = |project: Project, name: &str| {
@@ -651,6 +658,7 @@ fn the_sound_is_written_at_the_rate_that_was_asked_for() {
651 color: None,658 color: None,
652 fit: FitPolicy::default(),659 fit: FitPolicy::default(),
653 speed: Speed::NORMAL,660 speed: Speed::NORMAL,
661+ transform: None,
654 }],662 }],
655 ),663 ),
656 (664 (
@@ -668,11 +676,13 @@ fn the_sound_is_written_at_the_rate_that_was_asked_for() {
668 color: None,676 color: None,
669 fit: FitPolicy::default(),677 fit: FitPolicy::default(),
670 speed: Speed::NORMAL,678 speed: Speed::NORMAL,
679+ transform: None,
671 }],680 }],
672 ),681 ),
673 ],682 ],
674 Vec::new(),683 Vec::new(),
675 Vec::new(),684 Vec::new(),
685+ Vec::new(),
676 )686 )
677 .expect("a still under a song");687 .expect("a still under a song");
678 let meta = engine::VideoMeta {688 let meta = engine::VideoMeta {
@@ -726,6 +736,7 @@ fn a_silent_clip_exports_as_silence_over_its_own_span() {
726 color: None,736 color: None,
727 fit: FitPolicy::default(),737 fit: FitPolicy::default(),
728 speed: Speed::NORMAL,738 speed: Speed::NORMAL,
739+ transform: None,
729 };740 };
730 let project = Project::from_parts(741 let project = Project::from_parts(
731 vec![742 vec![
@@ -739,6 +750,7 @@ fn a_silent_clip_exports_as_silence_over_its_own_span() {
739 ],750 ],
740 Vec::new(),751 Vec::new(),
741 Vec::new(),752 Vec::new(),
753+ Vec::new(),
742 )754 )
743 .expect("a project whose middle take is silent");755 .expect("a project whose middle take is silent");
744 756
@@ -821,10 +833,12 @@ fn a_51_ac3_source_round_trips_through_a_wav() {
821 color: None,833 color: None,
822 fit: FitPolicy::default(),834 fit: FitPolicy::default(),
823 speed: Speed::NORMAL,835 speed: Speed::NORMAL,
836+ transform: None,
824 }],837 }],
825 )],838 )],
826 Vec::new(),839 Vec::new(),
827 Vec::new(),840 Vec::new(),
841+ Vec::new(),
828 )842 )
829 .expect("a one-source AC-3 project");843 .expect("a one-source AC-3 project");
830 let video = engine::demux::Demuxer::open(&source).expect("open the fixture").0;844 let video = engine::demux::Demuxer::open(&source).expect("open the fixture").0;
@@ -1140,10 +1154,12 @@ fn a_mono_timeline_exports_as_dual_mono_ogg() {
1140 color: None,1154 color: None,
1141 fit: FitPolicy::default(),1155 fit: FitPolicy::default(),
1142 speed: Speed::NORMAL,1156 speed: Speed::NORMAL,
1157+ transform: None,
1143 }],1158 }],
1144 )],1159 )],
1145 Vec::new(),1160 Vec::new(),
1146 Vec::new(),1161 Vec::new(),
1162+ Vec::new(),
1147 )1163 )
1148 .expect("a one-source mono project");1164 .expect("a one-source mono project");
1149 1165
crates/engine/tests/eq_audio.rsmodified+3 -0
@@ -66,6 +66,7 @@ fn clip(start: u32, source: usize, frames: u32) -> Clip {
66 color: None,66 color: None,
67 fit: FitPolicy::default(),67 fit: FitPolicy::default(),
68 speed: Speed::NORMAL,68 speed: Speed::NORMAL,
69+ transform: None,
69 }70 }
70 }71 }
71 72
@@ -80,6 +81,7 @@ fn project(audio: Vec<Clip>) -> Project {
80 ],81 ],
81 Vec::new(),82 Vec::new(),
82 Vec::new(),83 Vec::new(),
84+ Vec::new(),
83 )85 )
84 .expect("a one-source project")86 .expect("a one-source project")
85 }87 }
@@ -245,6 +247,7 @@ fn a_lane_is_equalized_before_the_mix_and_never_after_it() {
245 ],247 ],
246 Vec::new(),248 Vec::new(),
247 Vec::new(),249 Vec::new(),
250+ Vec::new(),
248 )251 )
249 .expect("a two-audio-lane project");252 .expect("a two-audio-lane project");
250 assert_eq!(p.audio_lanes().len(), 2, "both lanes hold something");253 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() {
244 link: Some(source as u32),244 link: Some(source as u32),
245 eq: None,245 eq: None,
246 color: None,246 color: None,
247+ transform: None,
247 fit: FitPolicy::default(),248 fit: FitPolicy::default(),
248 speed: Speed::NORMAL,249 speed: Speed::NORMAL,
249 };250 };
@@ -259,6 +260,7 @@ fn exports_at_the_project_resolution_with_the_watched_geometry() {
259 ],260 ],
260 Vec::new(),261 Vec::new(),
261 Vec::new(),262 Vec::new(),
263+ Vec::new(),
262 )264 )
263 .expect("a two-source project");265 .expect("a two-source project");
264 // The project's own resolution, which is neither source's: this is the266 // 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() {
329 link: Some(0),331 link: Some(0),
330 eq: None,332 eq: None,
331 color: None,333 color: None,
334+ transform: None,
332 fit: FitPolicy::default(),335 fit: FitPolicy::default(),
333 speed: Speed::NORMAL,336 speed: Speed::NORMAL,
334 };337 };
@@ -346,6 +349,7 @@ fn exports_the_audio_stream_the_timeline_plays() {
346 ],349 ],
347 Vec::new(),350 Vec::new(),
348 Vec::new(),351 Vec::new(),
352+ Vec::new(),
349 )353 )
350 .expect("a one-source project on stream 1");354 .expect("a one-source project on stream 1");
351 let out = out_path("stream1");355 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() {
245 link: None,245 link: None,
246 eq: None,246 eq: None,
247 color: None,247 color: None,
248+ transform: None,
248 fit: FitPolicy::default(),249 fit: FitPolicy::default(),
249 speed: Speed::NORMAL,250 speed: Speed::NORMAL,
250 };251 };
@@ -257,6 +258,7 @@ fn the_mp4_copy_follows_the_lane_that_holds_the_sound() {
257 ],258 ],
258 vec![],259 vec![],
259 vec![],260 vec![],
261+ vec![],
260 )262 )
261 .expect("valid parts");263 .expect("valid parts");
262 assert_eq!(264 assert_eq!(
@@ -309,14 +311,15 @@ fn two_audio_lanes_are_summed() {
309 link: None,311 link: None,
310 eq: None,312 eq: None,
311 color: None,313 color: None,
314+ transform: None,
312 fit: FitPolicy::default(),315 fit: FitPolicy::default(),
313 speed: Speed::NORMAL,316 speed: Speed::NORMAL,
314 };317 };
315 let a2 = project.add_lane(LaneKind::Audio);318 let a2 = project.add_lane(LaneKind::Audio);
316 assert!(project.place(a2, TOP_IN, doubled), "place the second lane");319 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();
318 assert_eq!(lanes.len(), 3, "V1, A1 and the new A2");321 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");
320 323
321 let (meta, _) = engine::demux::Demuxer::open(&asset("test_av.mp4")).unwrap();324 let (meta, _) = engine::demux::Demuxer::open(&asset("test_av.mp4")).unwrap();
322 let wav = |name: &str, project: Project| {325 let wav = |name: &str, project: Project| {
@@ -507,6 +510,7 @@ fn a_subtitle_lane_is_a_peer_and_every_media_path_refuses_it() {
507 vec![(LaneKind::Subtitle, vec![clip])],510 vec![(LaneKind::Subtitle, vec![clip])],
508 Vec::new(),511 Vec::new(),
509 Vec::new(),512 Vec::new(),
513+ Vec::new(),
510 )514 )
511 .expect_err("a file may not name one either");515 .expect_err("a file may not name one either");
512 assert!(516 assert!(
crates/engine/tests/opus_export.rsmodified+4 -0
@@ -92,6 +92,7 @@ fn project(video: &Path, sound: &Path, sound_in: u32) -> Project {
92 color: None,92 color: None,
93 fit: FitPolicy::default(),93 fit: FitPolicy::default(),
94 speed: Speed::NORMAL,94 speed: Speed::NORMAL,
95+ transform: None,
95 };96 };
96 // The sound is source **0** on purpose: the timeline takes its rate and its97 // The sound is source **0** on purpose: the timeline takes its rate and its
97 // width from the first source that has any, so a project whose first source98 // 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 {
109 ],110 ],
110 Vec::new(),111 Vec::new(),
111 Vec::new(),112 Vec::new(),
113+ Vec::new(),
112 )114 )
113 .expect("a picture lane and an audio lane")115 .expect("a picture lane and an audio lane")
114 }116 }
@@ -436,6 +438,7 @@ fn a_copied_picture_names_the_sound_it_was_written_with() {
436 color: None,438 color: None,
437 fit: FitPolicy::default(),439 fit: FitPolicy::default(),
438 speed: Speed::NORMAL,440 speed: Speed::NORMAL,
441+ transform: None,
439 };442 };
440 // The sound is source 0, for the reason [`project`] gives: the timeline443 // The sound is source 0, for the reason [`project`] gives: the timeline
441 // takes its rate and its width from the first source that has any.444 // 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() {
447 ],450 ],
448 Vec::new(),451 Vec::new(),
449 Vec::new(),452 Vec::new(),
453+ Vec::new(),
450 )454 )
451 .expect("a picture lane and an audio lane");455 .expect("a picture lane and an audio lane");
452 let out = out_path("copy_line");456 let out = out_path("copy_line");
crates/engine/tests/silence.rsmodified+6 -3
@@ -36,8 +36,8 @@ fn fixture() -> Project {
36 /// is one no save could load: this is that check, through the same door a load36 /// is one no save could load: this is that check, through the same door a load
37 /// takes.37 /// takes.
38 fn loadable(project: &Project) {38 fn loadable(project: &Project) {
39- let (sources, lanes, eq, color) = project.without_orphan_sources();39+ let (sources, lanes, eq, color, transform) = project.without_orphan_sources();
40- Project::from_parts(sources, lanes, eq, color).expect("the lanes still load");40+ Project::from_parts(sources, lanes, eq, color, transform).expect("the lanes still load");
41 }41 }
42 42
43 fn spans(project: &Project) -> (Vec<(u32, u32)>, Vec<(u32, u32)>) {43 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() {
150 color: None,150 color: None,
151 fit: Default::default(),151 fit: Default::default(),
152 speed: Speed::NORMAL,152 speed: Speed::NORMAL,
153+ transform: None,
153 };154 };
154 assert!(p.place(lane, 40, broll));155 assert!(p.place(lane, 40, broll));
155 let before = spans(&p);156 let before = spans(&p);
@@ -188,6 +189,7 @@ fn whole(source: usize, frames: u32) -> Clip {
188 color: None,189 color: None,
189 fit: Default::default(),190 fit: Default::default(),
190 speed: Speed::NORMAL,191 speed: Speed::NORMAL,
192+ transform: None,
191 }193 }
192 }194 }
193 195
@@ -370,7 +372,7 @@ fn scanning_a_clip_and_cutting_what_it_finds() {
370 // same dialect it always was -- no wire change went with this feature.372 // same dialect it always was -- no wire change went with this feature.
371 let dir = Scratch::dir("edith-silence");373 let dir = Scratch::dir("edith-silence");
372 let file = dir.join("cut.edith");374 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();
374 engine::edith::save(376 engine::edith::save(
375 &file,377 &file,
376 &sources,378 &sources,
@@ -380,6 +382,7 @@ fn scanning_a_clip_and_cutting_what_it_finds() {
380 p.subtitles(),382 p.subtitles(),
381 &eq,383 &eq,
382 &color,384 &color,
385+ &transform,
383 (1920, 1080),386 (1920, 1080),
384 None,387 None,
385 p.tone(),388 p.tone(),