forge
Explore
Log in

Don't you dare go Hollow

wip(engine): transform table threads through project/playback/proxy, .edith v20

Browse files at this commit

621274e126a3c47d336e6d4f673624e080b709e6Ahmet Kaan GümüşParent: d89279e
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() {
625625 link: None,
626626 eq: None,
627627 color: None,
628+ transform: None,
628629 fit: FitPolicy::default(),
629630 speed: Speed::NORMAL,
630631 };
@@ -998,6 +999,7 @@ fn a_menu_offers_only_what_applies_and_is_drawn_inside_the_window() {
998999 link: Some(1),
9991000 eq: None,
10001001 color: None,
1002+ transform: None,
10011003 fit: FitPolicy::default(),
10021004 speed: Speed::NORMAL,
10031005 };
@@ -1631,6 +1633,7 @@ fn a_copied_clip_is_renumbered_or_dropped_when_a_row_leaves_the_library() {
16311633 link: None,
16321634 eq: None,
16331635 color: None,
1636+ transform: None,
16341637 fit: Default::default(),
16351638 speed: Default::default(),
16361639 };
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() {
811811 link: None,
812812 eq: None,
813813 color: None,
814+ transform: None,
814815 fit: FitPolicy::Fit,
815816 speed: Speed::NORMAL,
816817 };
crates/app/src/tests/view.rsmodified+1 -0
@@ -157,6 +157,7 @@ fn the_marks_are_every_lane_the_playhead_and_the_start() {
157157 link,
158158 eq: None,
159159 color: None,
160+ transform: None,
160161 fit: Default::default(),
161162 speed: Default::default(),
162163 };
crates/engine/src/edith.rsmodified+67 -10
@@ -220,10 +220,12 @@ use crate::limiter::Limiter;
220220 use crate::project::{Clip, Lane, LaneKind, Source, Speed, SubClip};
221221 use crate::scale::FitPolicy;
222222 use crate::subtitle::SubtitleTrack;
223+use crate::transform::TransformParams;
223224
224225 /// What [`save`] writes. Read support goes back to `edith 1`; see the module
225226 /// docs for what those dialects looked like.
226-const MAGIC: &[u8] = b"edith 19";
227+const MAGIC: &[u8] = b"edith 20";
228+const MAGIC_V19: &[u8] = b"edith 19";
227229 const MAGIC_V18: &[u8] = b"edith 18";
228230 const MAGIC_V17: &[u8] = b"edith 17";
229231 const MAGIC_V16: &[u8] = b"edith 16";
@@ -265,6 +267,9 @@ pub struct Document {
265267 /// The colour table [`Clip::color`] indexes into, in file order. Empty for
266268 /// every dialect before v6.
267269 pub color: Vec<ColorParams>,
270+ /// The transform table [`Clip::transform`] indexes into, in file order.
271+ /// Empty for every dialect before v20.
272+ pub transform: Vec<TransformParams>,
268273 /// The project's own picture size. `None` for every dialect before v7 and
269274 /// for a v7 file that leaves it out, which both mean "source 0's picture".
270275 pub resolution: Option<(u32, u32)>,
@@ -333,6 +338,7 @@ pub fn save(
333338 subtitles: &[SubtitleTrack],
334339 eq: &[EqParams],
335340 color: &[ColorParams],
341+ transform: &[TransformParams],
336342 resolution: (u32, u32),
337343 fps: Option<f64>,
338344 tone: crate::tonemap::Preset,
@@ -354,8 +360,8 @@ pub fn save(
354360 let result = std::fs::File::create(&part)
355361 .and_then(|mut f| {
356362 f.write_all(&emit(
357- &dir, sources, lanes, gains, subs, subtitles, eq, color, resolution, fps, tone,
358- proxy, auto_proxy, encoder, limiter, sample_rate, playhead,
363+ &dir, sources, lanes, gains, subs, subtitles, eq, color, transform, resolution,
364+ fps, tone, proxy, auto_proxy, encoder, limiter, sample_rate, playhead,
359365 ))?;
360366 f.sync_all()
361367 })
@@ -396,6 +402,7 @@ fn emit(
396402 subtitles: &[SubtitleTrack],
397403 eq: &[EqParams],
398404 color: &[ColorParams],
405+ transform: &[TransformParams],
399406 resolution: (u32, u32),
400407 fps: Option<f64>,
401408 tone: crate::tonemap::Preset,
@@ -504,6 +511,16 @@ fn emit(
504511 .as_bytes(),
505512 );
506513 }
514+ // ...and the transform table, for the same reason and by the same rules.
515+ for p in transform {
516+ out.extend_from_slice(
517+ format!(
518+ "transform {:?}:{:?}:{:?}:{:?}:{:?}:{:?}:{:?}:{:?}\n",
519+ p.pos_x, p.pos_y, p.scale, p.rotate, p.crop_l, p.crop_r, p.crop_t, p.crop_b
520+ )
521+ .as_bytes(),
522+ );
523+ }
507524 // Lane by lane rather than interleaved by time: a lane reads as a list, the
508525 // parser gets its sortedness check for free from the order it is in, and
509526 // the lanes come back out in the order they are displayed in.
@@ -556,9 +573,10 @@ fn emit(
556573 let link = c.link.map_or("-".to_string(), |l| l.to_string());
557574 let eq = c.eq.map_or("-".to_string(), |e| e.to_string());
558575 let color = c.color.map_or("-".to_string(), |e| e.to_string());
576+ let transform = c.transform.map_or("-".to_string(), |e| e.to_string());
559577 out.extend_from_slice(
560578 format!(
561- "{keyword} {ord} {} {} {} {} {link} {eq} {color} {} {} {} {} {}\n",
579+ "{keyword} {ord} {} {} {} {} {link} {eq} {color} {} {} {} {} {} {transform}\n",
562580 c.start,
563581 c.in_frame,
564582 c.out_frame,
@@ -610,8 +628,10 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
610628 // The dialects that wrote a source line without its stream field. Reading
611629 // one is the whole of what "an old project still opens" means here.
612630 let streamless = v1 || first == MAGIC_V2;
613- // The one that carries a per-clip cross-dissolve into its successor...
614- let v19 = first == MAGIC;
631+ // The one that carries a per-clip transform (position/scale/rotate/crop)...
632+ let v20 = first == MAGIC;
633+ // ...the one that carries a per-clip cross-dissolve into its successor...
634+ let v19 = v20 || first == MAGIC_V19;
615635 // ...the one that carries a per-clip fade envelope...
616636 let v18 = v19 || first == MAGIC_V18;
617637 // ...the one that carries an explicit sound rate...
@@ -668,6 +688,10 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
668688 // Nothing before v5 equalizes anything, and nothing before v6 grades.
669689 eq: Vec::new(),
670690 color: Vec::new(),
691+ // Nothing before v20 places any clip anywhere but its fit policy's own
692+ // spot: the identity transform is what leaving a clip's index out
693+ // still means.
694+ transform: Vec::new(),
671695 // Nothing before v7 has a resolution of its own: source 0's picture is
672696 // what those projects were, and `None` is how the loader is told so.
673697 resolution: None,
@@ -972,6 +996,30 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
972996 tint: float(parts[3], n)?,
973997 });
974998 }
999+ b"transform" if v20 => {
1000+ if doc.lanes.iter().any(|(_, clips)| !clips.is_empty()) {
1001+ return Err(format!("line {n}: transform after a clip").into());
1002+ }
1003+ let f = fields(rest, 1, "transform", n)?;
1004+ let parts: Vec<&[u8]> = f[0].split(|&b| b == b':').collect();
1005+ if parts.len() != 8 {
1006+ return Err(format!(
1007+ "line {n}: transform wants 8 fields, found {}",
1008+ parts.len()
1009+ )
1010+ .into());
1011+ }
1012+ doc.transform.push(TransformParams {
1013+ pos_x: float(parts[0], n)?,
1014+ pos_y: float(parts[1], n)?,
1015+ scale: float(parts[2], n)?,
1016+ rotate: float(parts[3], n)?,
1017+ crop_l: float(parts[4], n)?,
1018+ crop_r: float(parts[5], n)?,
1019+ crop_t: float(parts[6], n)?,
1020+ crop_b: float(parts[7], n)?,
1021+ });
1022+ }
9751023 // v1: one lane, no placement, no groups. Every clip becomes one
9761024 // grouped video+audio pair laid where the queue reached, which is
9771025 // what the file always meant.
@@ -989,6 +1037,7 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
9891037 link: Some(doc.lanes[0].1.len() as u32),
9901038 eq: None,
9911039 color: None,
1040+ transform: None,
9921041 fit: FitPolicy::default(),
9931042 speed: Speed::NORMAL,
9941043 },
@@ -1100,16 +1149,18 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
11001149 if numbered && rest.is_empty() {
11011150 continue;
11021151 }
1103- // v18 grew the two fade fields, v19 the transition one, v8
1104- // the speed one, v7 the fit one, v6 the colour one and v5 the
1105- // eq one; every older dialect ends at the link.
1152+ // v20 grew the transform field, v18 the two fade fields, v19
1153+ // the transition one, v8 the speed one, v7 the fit one, v6
1154+ // the colour one and v5 the eq one; every older dialect ends
1155+ // at the link.
11061156 let want = 5
11071157 + usize::from(v5)
11081158 + usize::from(v6)
11091159 + usize::from(v7)
11101160 + usize::from(v8)
11111161 + 2 * usize::from(v18)
1112- + usize::from(v19);
1162+ + usize::from(v19)
1163+ + usize::from(v20);
11131164 let f = fields(rest, want, "clip", n)?;
11141165 let in_frame = number(f[1], n)?;
11151166 let out_frame = number(f[2], n)?;
@@ -1134,6 +1185,12 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
11341185 },
11351186 eq: table_index(f.get(5).copied(), doc.eq.len(), "eq", n)?,
11361187 color: table_index(f.get(6).copied(), doc.color.len(), "color", n)?,
1188+ transform: table_index(
1189+ f.get(12).copied(),
1190+ doc.transform.len(),
1191+ "transform",
1192+ n,
1193+ )?,
11371194 fit: fit_policy(f.get(7).copied(), n)?,
11381195 speed,
11391196 },
crates/engine/src/playback.rsmodified+10 -2
@@ -580,6 +580,7 @@ impl PlaybackSession {
580580 vec![(LaneKind::Video, Vec::new()), (LaneKind::Audio, Vec::new())],
581581 Vec::new(),
582582 Vec::new(),
583+ Vec::new(),
583584 )?;
584585 // Onto the emptied mapping: black picture, silence, zero duration.
585586 session.seek(0.);
@@ -628,6 +629,7 @@ impl PlaybackSession {
628629 link: None,
629630 eq: None,
630631 color: None,
632+ transform: None,
631633 fit: FitPolicy::default(),
632634 speed: Speed::NORMAL,
633635 };
@@ -636,6 +638,7 @@ impl PlaybackSession {
636638 vec![(LaneKind::Video, Vec::new()), (LaneKind::Audio, vec![clip])],
637639 Vec::new(),
638640 Vec::new(),
641+ Vec::new(),
639642 )?;
640643 // Every frame of this timeline is a gap, since no video lane covers
641644 // anything: `composite_span_at` says so and the black worker
@@ -714,6 +717,7 @@ impl PlaybackSession {
714717 link: None,
715718 eq: None,
716719 color: None,
720+ transform: None,
717721 fit: FitPolicy::default(),
718722 speed: Speed::NORMAL,
719723 };
@@ -724,6 +728,7 @@ impl PlaybackSession {
724728 vec![(LaneKind::Video, vec![clip]), (LaneKind::Audio, Vec::new())],
725729 Vec::new(),
726730 Vec::new(),
731+ Vec::new(),
727732 )?;
728733 let span = project.composite_span_at(0);
729734 // The placeholder the first seek supersedes, opened here for `open`'s
@@ -1014,7 +1019,8 @@ impl PlaybackSession {
10141019 // whole to reach one track: a film whose project names many of its
10151020 // tracks is one walk here rather than one per row.
10161021 let subtitles = crate::subtitle::open_all(&doc.subtitles);
1017- let project = Project::from_parts(doc.sources, doc.lanes, doc.eq, doc.color)?
1022+ let project =
1023+ Project::from_parts(doc.sources, doc.lanes, doc.eq, doc.color, doc.transform)?
10181024 .with_mix(&doc.gains, doc.limiter)
10191025 .with_tone(doc.tone)
10201026 // The palette before what is placed on it: a caption names a row of
@@ -1306,7 +1312,7 @@ impl PlaybackSession {
13061312 if self.project.sources().is_empty() {
13071313 return Err("this project names no file: there is nothing to save".into());
13081314 }
1309- let (sources, lanes, eq, color) = self.project.without_orphan_sources();
1315+ let (sources, lanes, eq, color, transform) = self.project.without_orphan_sources();
13101316 let playhead = secs_to_frame(self.now(), self.meta.frame_rate)
13111317 .min(self.project.timeline_frames().saturating_sub(1));
13121318 crate::edith::save(
@@ -1326,6 +1332,7 @@ impl PlaybackSession {
13261332 self.project.subtitles(),
13271333 &eq,
13281334 &color,
1335+ &transform,
13291336 (self.meta.width, self.meta.height),
13301337 // ...and the rate it was cut at, which nothing else in the file
13311338 // says: a timeline of stills and songs used to come back at
@@ -2689,6 +2696,7 @@ impl PlaybackSession {
26892696 link: None,
26902697 eq: None,
26912698 color: None,
2699+ transform: None,
26922700 fit: FitPolicy::default(),
26932701 speed: Speed::NORMAL,
26942702 };
crates/engine/src/project.rsmodified+20 -0
@@ -1308,6 +1308,7 @@ impl Project {
13081308 link: Some(self.new_link()),
13091309 eq: None,
13101310 color: None,
1311+ transform: None,
13111312 fit: FitPolicy::default(),
13121313 speed: Speed::NORMAL,
13131314 };
@@ -4593,6 +4594,7 @@ impl Project {
45934594 lanes: self.lanes.clone(),
45944595 eq: self.eq.clone(),
45954596 color: self.color.clone(),
4597+ transform: self.transform.clone(),
45964598 history: Vec::new(),
45974599 redo: Vec::new(),
45984600 next_link: self.next_link,
@@ -4934,6 +4936,20 @@ fn color_finite(p: &ColorParams) -> bool {
49344936 && p.tint.is_finite()
49354937 }
49364938
4939+/// The same for a transform: [`crate::scale`] clamps a non-finite value to
4940+/// identity at read time, but a value that cannot round-trip has no business
4941+/// reaching the model.
4942+fn transform_finite(p: &TransformParams) -> bool {
4943+ p.pos_x.is_finite()
4944+ && p.pos_y.is_finite()
4945+ && p.scale.is_finite()
4946+ && p.rotate.is_finite()
4947+ && p.crop_l.is_finite()
4948+ && p.crop_r.is_finite()
4949+ && p.crop_t.is_finite()
4950+ && p.crop_b.is_finite()
4951+}
4952+
49374953 fn sorted_disjoint(clips: &[Clip]) -> bool {
49384954 clips.iter().all(|c| c.out_frame > c.in_frame)
49394955 && clips.windows(2).all(|w| w[0].end() <= w[1].start)
@@ -5286,6 +5302,7 @@ mod tests {
52865302 link: None,
52875303 eq: None,
52885304 color: None,
5305+ transform: None,
52895306 fit: FitPolicy::default(),
52905307 speed: Speed::NORMAL,
52915308 }
@@ -6756,6 +6773,7 @@ mod tests {
67566773 link: None,
67576774 eq: None,
67586775 color: None,
6776+ transform: None,
67596777 fit: FitPolicy::Fit,
67606778 speed: Speed::NORMAL,
67616779 };
@@ -8283,6 +8301,7 @@ mod tests {
82838301 link: Some(link),
82848302 eq: None,
82858303 color: None,
8304+ transform: None,
82868305 fit: FitPolicy::default(),
82878306 speed: Speed::NORMAL,
82888307 };
@@ -9063,6 +9082,7 @@ mod tests {
90639082 link: Some(link),
90649083 eq: None,
90659084 color: None,
9085+ transform: None,
90669086 fit: FitPolicy::default(),
90679087 speed: Speed::NORMAL,
90689088 };
crates/engine/src/proxy.rsmodified+2 -0
@@ -497,6 +497,7 @@ fn started(source: &Path, only_if: fn(&VideoMeta) -> bool) -> crate::Result<Opti
497497 link: None,
498498 eq: None,
499499 color: None,
500+ transform: None,
500501 fit: FitPolicy::default(),
501502 speed: Speed::NORMAL,
502503 };
@@ -505,6 +506,7 @@ fn started(source: &Path, only_if: fn(&VideoMeta) -> bool) -> crate::Result<Opti
505506 vec![(LaneKind::Video, vec![clip])],
506507 Vec::new(),
507508 Vec::new(),
509+ Vec::new(),
508510 )?;
509511 let bitrate =
510512 (f64::from(width) * f64::from(height) * meta.frame_rate * BITS_PER_PIXEL) as u64;