forge
Explore
Log in

Don't you dare go Hollow

The transform reaches both render paths

Browse files at this commit

f4e379fb38edca6c02b6f439a6cc9cfee50d37f8Ahmet Kaan GümüşParent: 5984e27
  • feat
    • the transform reaches both render paths
Show full message
✨ feat(engine): the transform reaches both render paths
crates/engine/src/decode.rsmodified+49 -4
@@ -17,6 +17,7 @@ use crate::hw::HwSession;
1717 use crate::project::Speed;
1818 use crate::scale::Composer;
1919 use crate::tonemap::{self, ToneMapper};
20+use crate::transform::TransformParams;
2021
2122 /// One decoded picture, ready to hand to a renderer.
2223 pub struct Frame {
@@ -176,6 +177,7 @@ struct SpanCmd {
176177 start: u32,
177178 end: u32,
178179 color: ColorParams,
180+ transform: TransformParams,
179181 canvas: Composer,
180182 tone: tonemap::Preset,
181183 /// The clip's own playback speed ([`crate::project::Clip::speed`]), for
@@ -308,6 +310,7 @@ impl Worker {
308310 start: u32,
309311 end: u32,
310312 color: ColorParams,
313+ transform: TransformParams,
311314 canvas: Composer,
312315 tone: tonemap::Preset,
313316 speed: Speed,
@@ -331,6 +334,7 @@ impl Worker {
331334 start,
332335 end,
333336 color,
337+ transform,
334338 canvas,
335339 tone,
336340 speed,
@@ -433,6 +437,9 @@ impl DecodeSession {
433437 start_frame,
434438 end_frame,
435439 ColorParams::default(),
440+ // No clip, no transform either: the file-level API hands back the
441+ // pictures the file holds, untouched.
442+ TransformParams::default(),
436443 // No project, no canvas: the file-level API hands back the
437444 // pictures the file holds, at the size it holds them.
438445 Composer::passthrough(),
@@ -512,6 +519,7 @@ impl DecodeSession {
512519 start_frame: u32,
513520 len: u32,
514521 color: ColorParams,
522+ transform: TransformParams,
515523 canvas: Composer,
516524 ) -> crate::Result<FrameStream> {
517525 let still = Still::open(path)?;
@@ -538,6 +546,7 @@ impl DecodeSession {
538546 // the project is watching.
539547 let first = Render::new(
540548 color,
549+ transform,
541550 ColorDescription::default(),
542551 canvas,
543552 tonemap::Preset::default(),
@@ -610,6 +619,7 @@ impl DecodeSession {
610619 start_frame: u32,
611620 end_frame: u32,
612621 color: ColorParams,
622+ transform: TransformParams,
613623 canvas: Composer,
614624 tone: tonemap::Preset,
615625 ) -> crate::Result<(VideoMeta, FrameStream)> {
@@ -650,6 +660,7 @@ impl DecodeSession {
650660 start_frame,
651661 end_frame,
652662 color,
663+ transform,
653664 canvas,
654665 tone,
655666 // A file-level open has no clip and no speed to skip frames
@@ -677,6 +688,7 @@ impl DecodeSession {
677688 start_frame: u32,
678689 end_frame: u32,
679690 color: ColorParams,
691+ transform: TransformParams,
680692 canvas: Composer,
681693 tone: tonemap::Preset,
682694 speed: Speed,
@@ -687,6 +699,7 @@ impl DecodeSession {
687699 start_frame,
688700 end_frame,
689701 color,
702+ transform,
690703 canvas,
691704 tone,
692705 speed,
@@ -710,6 +723,7 @@ fn span_worker(
710723 start_frame: u32,
711724 end_frame: u32,
712725 color: ColorParams,
726+ transform: TransformParams,
713727 canvas: Composer,
714728 tone: tonemap::Preset,
715729 speed: Speed,
@@ -740,6 +754,7 @@ fn span_worker(
740754 start: start_frame,
741755 end: end_frame,
742756 color,
757+ transform,
743758 canvas,
744759 tone,
745760 speed,
@@ -919,6 +934,7 @@ fn run_span(
919934 start,
920935 end,
921936 color,
937+ transform,
922938 canvas,
923939 tone,
924940 speed,
@@ -947,7 +963,7 @@ fn run_span(
947963 // The stream's own colour and peak brightness: properties of the stream, so
948964 // neither can change while one range decodes -- but the grade, the canvas
949965 // 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);
951967 if let Some(reused) = opened.position_hw(path, start) {
952968 // Cancelled during the init (or the seek): leave without decoding.
953969 if abort.hit() {
@@ -1007,6 +1023,9 @@ fn run_span(
10071023 /// project resolution, byte for byte and allocation for allocation.
10081024 struct Render {
10091025 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,
10101029 /// What the source's samples mean -- the stream's own matrix and range,
10111030 /// which is what the conversion below is done in rather than the BT.601 it
10121031 /// used to assume of every file.
@@ -1021,6 +1040,10 @@ struct Render {
10211040 /// across the worker's whole range. Empty unless the clip needs one: it is
10221041 /// tone-mapped in place, graded in place, or both.
10231042 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>),
10241047 }
10251048
10261049 /// What [`Render::frame`] converts a tone-mapped picture in: the tone map's
@@ -1038,6 +1061,7 @@ impl Render {
10381061 /// reference rendition reads (see [`tonemap::Preset`]).
10391062 fn new(
10401063 color: ColorParams,
1064+ transform: TransformParams,
10411065 desc: ColorDescription,
10421066 canvas: Composer,
10431067 preset: tonemap::Preset,
@@ -1045,6 +1069,7 @@ impl Render {
10451069 ) -> Self {
10461070 Self {
10471071 color,
1072+ transform,
10481073 desc,
10491074 canvas,
10501075 // corner-cut: the ceiling is that the map reads limited-range codes
@@ -1058,6 +1083,7 @@ impl Render {
10581083 Transfer::Hlg => Some(ToneMapper::new(tonemap::Transfer::Hlg, preset, peak)),
10591084 },
10601085 graded: (Vec::new(), Vec::new(), Vec::new()),
1086+ placed: (Vec::new(), Vec::new(), Vec::new()),
10611087 }
10621088 }
10631089
@@ -1071,6 +1097,12 @@ impl Render {
10711097 height: u32,
10721098 ) -> Frame {
10731099 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;
10741106 // Everything that has to happen to the samples before the canvas sees
10751107 // them, on one copy: the tone map (HDR streams only) and, unless the
10761108 // conversion below can fuse it, the grade. An SDR stream that is either
@@ -1080,7 +1112,8 @@ impl Render {
10801112 // picture a viewer is shown, so its brightness and saturation mean what
10811113 // they say in the SDR the tone map just produced, not in the 10-stop
10821114 // 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())
10841117 {
10851118 let (gy, gu, gv) = &mut self.graded;
10861119 gy.clear();
@@ -1104,7 +1137,7 @@ impl Render {
11041137 } else {
11051138 (y, u, v, self.desc)
11061139 };
1107- if passthrough {
1140+ if skip_placement {
11081141 return Frame {
11091142 index,
11101143 width,
@@ -1120,7 +1153,15 @@ impl Render {
11201153 ),
11211154 };
11221155 }
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+ };
11241165 Frame {
11251166 index,
11261167 width,
@@ -1384,6 +1425,7 @@ mod tests {
13841425 0,
13851426 u32::MAX,
13861427 ColorParams::default(),
1428+ TransformParams::default(),
13871429 Composer::passthrough(),
13881430 tonemap::Preset::default(),
13891431 Speed::NORMAL,
@@ -1405,6 +1447,7 @@ mod tests {
14051447 0,
14061448 u32::MAX,
14071449 ColorParams::default(),
1450+ TransformParams::default(),
14081451 Composer::passthrough(),
14091452 tonemap::Preset::default(),
14101453 )
@@ -1453,6 +1496,7 @@ mod tests {
14531496 0,
14541497 u32::MAX,
14551498 ColorParams::default(),
1499+ TransformParams::default(),
14561500 Composer::passthrough(),
14571501 tonemap::Preset::default(),
14581502 Speed::NORMAL,
@@ -1536,6 +1580,7 @@ mod tests {
15361580 0,
15371581 u32::MAX,
15381582 ColorParams::default(),
1583+ TransformParams::default(),
15391584 Composer::passthrough(),
15401585 tonemap::Preset::default(),
15411586 )
crates/engine/src/export.rsmodified+38 -3
@@ -82,6 +82,7 @@ use crate::project::{Lane, LaneKind, Project, Rate};
8282 use crate::scale::{blend_i420, Composer};
8383 use crate::subtitle::{Cue, SubtitleTrack};
8484 use crate::tonemap::{self, ToneMapper};
85+use crate::transform::TransformParams;
8586
8687 /// Progress is reported in permille: an atomic integer the render loop can read
8788 /// without a lock, fine enough for any progress bar.
@@ -1083,8 +1084,10 @@ struct Dissolve<'a> {
10831084 mapper: Option<&'a ToneMapper>,
10841085 remap: Option<(Matrix, Matrix)>,
10851086 grade: Option<crate::color::ColorParams>,
1087+ transform: TransformParams,
10861088 canvas: Composer,
10871089 graded: (Vec<u8>, Vec<u8>, Vec<u8>),
1090+ transformed: (Vec<u8>, Vec<u8>, Vec<u8>),
10881091 }
10891092
10901093 /// The track's cues where the *exported* timeline puts them, which is the only
@@ -1643,6 +1646,14 @@ impl CopyPlan {
16431646 {
16441647 return None;
16451648 }
1649+ // A moved, scaled, rotated or cropped clip is a different picture
1650+ // than the source's own packets, exactly as a grade is.
1651+ if project
1652+ .composite_transform_at(span.start)
1653+ .is_some_and(|params| !params.is_identity())
1654+ {
1655+ return None;
1656+ }
16461657 let path = &entries.get(source)?.path;
16471658 if sources.get(source)?.is_none() {
16481659 if !crate::demux::is_matroska(path) {
@@ -2537,6 +2548,9 @@ fn run(
25372548 && project
25382549 .composite_color_at(span.start)
25392550 .is_none_or(|params| params.is_identity())
2551+ && project
2552+ .composite_transform_at(span.start)
2553+ .is_none_or(|params| params.is_identity())
25402554 && dissolve.is_none();
25412555 let want = untouched.then(|| encoder.dma_want(meta)).flatten();
25422556 // Opened at the file's own frame, which is the only place the
@@ -2566,7 +2580,12 @@ fn run(
25662580 // is touched. Scratch outside the frame loop: it is refilled per frame
25672581 // and its allocation survives the whole span.
25682582 let grade = project.composite_color_at(span.start).copied();
2583+ let transform = project
2584+ .composite_transform_at(span.start)
2585+ .copied()
2586+ .unwrap_or_default();
25692587 let mut graded = (Vec::new(), Vec::new(), Vec::new());
2588+ let mut transformed = (Vec::new(), Vec::new(), Vec::new());
25702589 // ...and the canvas it is placed on, which is where a source of another
25712590 // resolution becomes a picture at the project's. The same `Composer`
25722591 // playback composes with, given the same policy, so an export is what
@@ -2595,12 +2614,17 @@ fn run(
25952614 mapper: b_mapper,
25962615 remap: b_remap,
25972616 grade: project.composite_color_at(b_start).copied(),
2617+ transform: project
2618+ .composite_transform_at(b_start)
2619+ .copied()
2620+ .unwrap_or_default(),
25982621 canvas: Composer::new(
25992622 meta.width,
26002623 meta.height,
26012624 project.composite_fit_at(b_start),
26022625 ),
26032626 graded: (Vec::new(), Vec::new(), Vec::new()),
2627+ transformed: (Vec::new(), Vec::new(), Vec::new()),
26042628 })
26052629 })
26062630 .transpose()?;
@@ -2688,9 +2712,11 @@ fn run(
26882712 width,
26892713 height,
26902714 grade,
2715+ transform,
26912716 remap,
26922717 mapper,
26932718 &mut graded,
2719+ &mut transformed,
26942720 &mut canvas,
26952721 )),
26962722 };
@@ -2718,8 +2744,9 @@ fn run(
27182744 }
27192745 Some(Frame::Pixels(by, bu, bv, bw, bh)) => {
27202746 let (by, bu, bv, _, _) = place_picture(
2721- by, bu, bv, bw, bh, d.grade, d.remap, d.mapper,
2722- &mut d.graded, &mut d.canvas,
2747+ by, bu, bv, bw, bh, d.grade, d.transform, d.remap,
2748+ d.mapper, &mut d.graded, &mut d.transformed,
2749+ &mut d.canvas,
27232750 );
27242751 let idx_in_window = done_here + r - d.tail_start;
27252752 let t = dissolve_weight(idx_in_window, d.window);
@@ -2854,9 +2881,11 @@ fn place_picture<'a>(
28542881 width: u32,
28552882 height: u32,
28562883 grade: Option<crate::color::ColorParams>,
2884+ transform: TransformParams,
28572885 remap: Option<(Matrix, Matrix)>,
28582886 mapper: Option<&ToneMapper>,
28592887 graded: &'a mut (Vec<u8>, Vec<u8>, Vec<u8>),
2888+ transformed: &'a mut (Vec<u8>, Vec<u8>, Vec<u8>),
28602889 canvas: &'a mut Composer,
28612890 ) -> (&'a [u8], &'a [u8], &'a [u8], u32, u32) {
28622891 // The planes are borrowed from the decoder (and `Black::picture` hands the
@@ -2891,7 +2920,13 @@ fn place_picture<'a>(
28912920 };
28922921 // Grade first, place second: the grade is the clip's own pixels and the
28932922 // bars around them are not the clip (see `scale::Composer`).
2894- canvas.place(y, u, v, width, height)
2923+ if transform.is_identity() {
2924+ canvas.place(y, u, v, width, height)
2925+ } else {
2926+ let (py, pu, pv, w, h) = canvas.place_transformed(y, u, v, width, height, &transform);
2927+ *transformed = (py, pu, pv);
2928+ (&transformed.0[..], &transformed.1[..], &transformed.2[..], w, h)
2929+ }
28952930 }
28962931
28972932 /// Which matrix pair a span's samples are rewritten by on the way into a file
crates/engine/src/playback.rsmodified+17 -0
@@ -28,6 +28,7 @@ use crate::demux::{Codec, Demuxer, VideoMeta};
2828 use crate::eq::EqParams;
2929 use crate::project::{Clip, Edge, Lane, LaneKind, Project, Rate, Source, Span, Speed, SubClip};
3030 use crate::scale::{Composer, FitPolicy};
31+use crate::transform::TransformParams;
3132
3233 /// How long the feeder waits out a full ring. The ring holds a second, so this
3334 /// only has to be short next to that; it costs one wakeup per 10 ms of audio.
@@ -510,6 +511,7 @@ impl PlaybackSession {
510511 0,
511512 u32::MAX,
512513 ColorParams::default(),
514+ TransformParams::default(),
513515 Composer::passthrough(),
514516 // The default rendition: a file just opened is a project nobody has
515517 // picked one for, exactly as it is a project nobody has graded.
@@ -738,6 +740,7 @@ impl PlaybackSession {
738740 0,
739741 span.map_or(1, |s| s.len),
740742 ColorParams::default(),
743+ TransformParams::default(),
741744 Composer::passthrough(),
742745 )?;
743746 Ok(Self {
@@ -870,6 +873,7 @@ impl PlaybackSession {
870873 0,
871874 1,
872875 ColorParams::default(),
876+ TransformParams::default(),
873877 Composer::passthrough(),
874878 )?;
875879 (meta, stream)
@@ -879,6 +883,7 @@ impl PlaybackSession {
879883 0,
880884 u32::MAX,
881885 ColorParams::default(),
886+ TransformParams::default(),
882887 Composer::passthrough(),
883888 // The saved rendition, from the document rather than from the
884889 // project (which is built below): this placeholder is what the
@@ -1603,6 +1608,10 @@ impl PlaybackSession {
16031608 .composite_color_at(start)
16041609 .copied()
16051610 .unwrap_or_default(),
1611+ self.project
1612+ .composite_transform_at(start)
1613+ .copied()
1614+ .unwrap_or_default(),
16061615 Composer::new(
16071616 self.meta.width,
16081617 self.meta.height,
@@ -1646,6 +1655,11 @@ impl PlaybackSession {
16461655 .composite_color_at(start)
16471656 .copied()
16481657 .unwrap_or_default();
1658+ let transform = self
1659+ .project
1660+ .composite_transform_at(start)
1661+ .copied()
1662+ .unwrap_or_default();
16491663 // ...and the canvas it is placed on: the project's resolution
16501664 // and this clip's own fit policy, constant across the span for
16511665 // the reason the grade is. Built where it is handed over rather
@@ -1684,6 +1698,7 @@ impl PlaybackSession {
16841698 start_frame,
16851699 end_frame,
16861700 color,
1701+ transform,
16871702 canvas(),
16881703 tone,
16891704 decode_speed,
@@ -1698,6 +1713,7 @@ impl PlaybackSession {
16981713 start_frame,
16991714 end_frame,
17001715 color,
1716+ transform,
17011717 canvas(),
17021718 tone,
17031719 decode_speed,
@@ -3578,6 +3594,7 @@ fn matches_timeline(
35783594 0,
35793595 0,
35803596 ColorParams::default(),
3597+ TransformParams::default(),
35813598 Composer::passthrough(),
35823599 // A zero-length range decodes nothing, so no table is built and the
35833600 // rendition cannot matter here.