forge
Explore
Log in

Don't you dare go Hollow

The film's declared HDR grade becomes visible

Browse files at this commit

c2943bb4e81e4cb8157b27891d7cf1edbd7d9f4eAhmet Kaan GümüşParent: bdb07d9e88fbc8
  • feat
    • the film's declared HDR grade becomes visible
Show full message
✨ feat(settings): the film's declared HDR grade becomes visible

The engine has always parsed mastering-display peak, MaxCLL and MaxFALL from
both the MKV and MP4 paths and fed them to the tonemapper; nothing above the
engine could see them. PlaybackSession now carries the ContentLight, and two
read-only rows under HDR tonemap state the numbers.

Read-only because no field exists anywhere to persist an override — a readout
of what the file declares, not an invented setting.
crates/app/src/tests/layout.rsmodified+33 -0
@@ -2272,3 +2272,36 @@ fn settings_project_rows_have_no_bare_noun_placeholder() {
22722272 );
22732273 }
22742274 }
2275+
2276+/// The HDR reference rows must read the file's own declared numbers off
2277+/// [`engine::colorspace::ContentLight`] -- not invent a monitor override the
2278+/// engine has nowhere to persist -- and must fall back to the page's one
2279+/// established empty state (a bare `—` in `INK4`, [`row_ink`]/[`row_static`]'s
2280+/// own idiom) rather than a second placeholder idiom. No `TestAppContext`
2281+/// here either, so this is the same source-scan the guard above it is.
2282+#[test]
2283+fn hdr_reference_rows_read_content_light_and_use_the_established_empty_state() {
2284+ let source = src_text("ui/settings_stance.rs");
2285+ let project_start = source.find("fn project_section(").expect("the project section");
2286+ let editor_start = source.find("fn editor_section(").expect("the editor section");
2287+ let project_body = &source[project_start..editor_start];
2288+
2289+ assert!(project_body.contains("settings-hdr-reference"), "the HDR reference row is missing");
2290+ assert!(project_body.contains("settings-content-light"), "the content-light row is missing");
2291+
2292+ // Reads the real declared numbers, not an invented default or a fixed
2293+ // string standing in for one.
2294+ for field in ["mastering_max", "max_cll", "max_fall"] {
2295+ assert!(project_body.contains(field), "the HDR reference rows do not read ContentLight::{field}");
2296+ }
2297+
2298+ // No override field exists on the engine side to write one into, so the
2299+ // row must never claim a picker/opener the way every other PROJECT row
2300+ // does -- it is built with `row_static`, not `row`/`row_ink`.
2301+ assert!(project_body.contains("row_static(\n \"settings-hdr-reference\""), "the HDR reference row must be read-only (row_static), not a picker");
2302+ assert!(project_body.contains("row_static(\n \"settings-content-light\""), "the content-light row must be read-only (row_static), not a picker");
2303+
2304+ // The established empty state: a bare "—" reused, never a second idiom
2305+ // ("N/A", "None", "Unknown"...) invented for the same absence.
2306+ assert!(project_body.contains("\"—\".to_string()"), "the HDR reference rows must reuse the page's own empty-state dash");
2307+}
crates/app/src/ui/settings_stance.rsmodified+89 -9
@@ -21,16 +21,20 @@
2121 //! Values apply live through those same doors; there is no Apply button here
2222 //! to be inconsistent with the rest of the room.
2323 //!
24-//! Seams left for other builders (this task's scope boundary): the HDR
25-//! mastering-display target row (a monitor fact, not in `inspector.rs`'s own
26-//! project section yet) has no row here either -- it plugs into
27-//! `project_section` below, beside the tonemap row it is the pair of. A
28-//! finer fps/sample-rate/tone picker is the same builder's to extend; this
29-//! page only ever asks for [`Pick::Fps`]/[`Pick::SampleRate`]/[`Pick::Tone`]
24+//! Seams left for other builders (this task's scope boundary): a finer
25+//! fps/sample-rate/tone picker is the same builder's to extend; this page
26+//! only ever asks for [`Pick::Fps`]/[`Pick::SampleRate`]/[`Pick::Tone`]
3027 //! exactly as `inspector.rs`'s legacy panel already does.
28+//!
29+//! The HDR reference numbers beside the tonemap row (`HDR reference` and
30+//! `Content light`) are the *file's* declared light level
31+//! ([`engine::colorspace::ContentLight`]), not a monitor fact -- read-only,
32+//! since nothing in [`engine::project::Project`] holds a place to persist an
33+//! override into.
3134
3235 use crate::*;
3336 use crate::ui::type_scale;
37+use engine::colorspace::ContentLight;
3438
3539 /// A 9px uppercase Archivo section head, `ink3` -- [`dock_stance::section_head`]'s
3640 /// exact shape, repeated rather than imported across a `pub(crate)` seam for
@@ -110,6 +114,51 @@ fn row_ink(
110114 )
111115 }
112116
117+/// [`row_ink`] with no opener: a readout rather than a picker, for a value
118+/// this editor cannot set because nothing behind it can hold a pick --
119+/// [`engine::playback::PlaybackSession`] has no field to persist one into.
120+/// No `cursor_pointer`, no hover paint, no click: the row must not read as a
121+/// button that does nothing when pressed. The hint still names where the
122+/// number came from, since a reader who wants that detail should get it from
123+/// the same door every other row's hint answers from.
124+fn row_static(
125+ id: &'static str,
126+ label_text: &'static str,
127+ value: impl Into<SharedString>,
128+ hint: &'static str,
129+ value_ink: u32,
130+) -> impl IntoElement {
131+ let value: SharedString = value.into();
132+ let hint: SharedString = hint.into();
133+ let label_style = type_scale::label(type_scale::LABEL_ROW_PX, gpui::FontWeight::MEDIUM);
134+ let value_style = type_scale::mono(type_scale::LABEL_ROW_PX, gpui::FontWeight::MEDIUM);
135+ div()
136+ .id(id)
137+ .flex_none()
138+ .flex()
139+ .items_center()
140+ .justify_between()
141+ .h(px(CONTROL_H))
142+ .px(px(8.))
143+ .rounded(px(3.))
144+ .tooltip(move |_, cx| cx.new(|_| Tip(hint.clone())).into())
145+ .child(
146+ div()
147+ .font(label_style.font)
148+ .text_size(label_style.size)
149+ .text_color(rgb(INK2()))
150+ .child(label_text),
151+ )
152+ .child(
153+ div()
154+ .flex_none()
155+ .font(value_style.font)
156+ .text_size(value_style.size)
157+ .text_color(rgb(value_ink))
158+ .child(value),
159+ )
160+}
161+
113162 /// PROJECT: the canvas every clip is composed onto, the rate it is cut at,
114163 /// the HDR rendition it is watched in, and the mix everything sums into --
115164 /// [`inspector.rs`]'s own four-plus-Mix list, ported rather than
@@ -140,6 +189,23 @@ fn project_section(player: &Player, cx: &mut Context<Player>) -> impl IntoElemen
140189 Some(session) => (format!("HDR {}", tone_label(session.tone())), INK1()),
141190 None => ("—".to_string(), INK4()),
142191 };
192+ // The reference row's own numbers: what source 0's file actually declared
193+ // ([`engine::colorspace::ContentLight`], read at open by
194+ // [`engine::playback::PlaybackSession::content_light`]) -- read-only,
195+ // since nothing in [`engine::project::Project`] holds an override to
196+ // persist one into. `—` for a project with no session, and for a session
197+ // whose file is SDR or simply declared nothing (most files declare
198+ // nothing here at all).
199+ let light = player.session.as_ref().map_or(ContentLight::default(), engine::playback::PlaybackSession::content_light);
200+ let (master_val, master_ink) = match (&player.session, light.mastering_max) {
201+ (Some(_), Some(nits)) => (format!("{nits:.0} nits"), INK1()),
202+ _ => ("—".to_string(), INK4()),
203+ };
204+ let (content_val, content_ink) = match (&player.session, light.max_cll, light.max_fall) {
205+ (Some(_), Some(cll), Some(fall)) => (format!("{cll:.0}/{fall:.0} nits"), INK1()),
206+ (Some(_), Some(cll), None) => (format!("{cll:.0} nits"), INK1()),
207+ _ => ("—".to_string(), INK4()),
208+ };
143209 div()
144210 .flex_none()
145211 .flex()
@@ -172,9 +238,6 @@ fn project_section(player: &Player, cx: &mut Context<Player>) -> impl IntoElemen
172238 player,
173239 cx.listener(|this, event: &ClickEvent, _, cx| this.open_picker(Pick::SampleRate, event.position(), cx)),
174240 ))
175- // hook: the mastering-display target (a monitor peak-nits fact, not
176- // yet in `inspector.rs`'s own project section) is this row's pair --
177- // another builder's row, plugged in right here once it exists.
178241 .child(row_ink(
179242 "settings-tonemap",
180243 "HDR tonemap",
@@ -184,6 +247,23 @@ fn project_section(player: &Player, cx: &mut Context<Player>) -> impl IntoElemen
184247 cx.listener(|this, event: &ClickEvent, _, cx| this.open_picker(Pick::Tone, event.position(), cx)),
185248 tone_ink,
186249 ))
250+ // The tonemap row's pair: what the file actually declared, read-only
251+ // ([`row_static`] -- there is nowhere in the project to persist a
252+ // pick even if this page offered one).
253+ .child(row_static(
254+ "settings-hdr-reference",
255+ "HDR reference",
256+ master_val,
257+ "the mastering display's own peak white, in cd/m^2, as the grade declared it -- what a 'Reference' tonemap targets before it ever looks at this film's own pixels",
258+ master_ink,
259+ ))
260+ .child(row_static(
261+ "settings-content-light",
262+ "Content light",
263+ content_val,
264+ "MaxCLL/MaxFALL: the brightest single pixel and the brightest frame average measured in the finished encode -- what a 'Reference' tonemap actually rolls off from when the file declares it, ahead of the mastering peak above",
265+ content_ink,
266+ ))
187267 .child(row(
188268 "settings-mix",
189269 "Mix",
crates/engine/src/playback.rsmodified+36 -1
@@ -22,7 +22,7 @@ use crate::ao::AoSession;
2222 use crate::audio::{AudioChunk, AudioSession};
2323 use crate::clock::{ClockSource, PlaybackClock};
2424 use crate::color::ColorParams;
25-use crate::colorspace::ColorDescription;
25+use crate::colorspace::{ColorDescription, ContentLight};
2626 use crate::decode::{Backend, BackendCell, DecodeSession, Frame, Worker};
2727 use crate::demux::{Codec, Demuxer, VideoMeta};
2828 use crate::eq::EqParams;
@@ -312,6 +312,13 @@ pub struct PlaybackSession {
312312 /// `resolution` line makes it after that. Every clip is composed onto it, so
313313 /// a file of another size is a placed picture rather than a refusal.
314314 meta: VideoMeta,
315+ /// What source 0's own file declared about how bright it gets
316+ /// ([`crate::colorspace::ContentLight`]) -- MaxCLL/MaxFALL and the
317+ /// mastering display's peak/black, read once at open exactly as `native`
318+ /// is, since the value is a property of the file and never changes under
319+ /// a running session. [`ContentLight::default()`] (every field `None`)
320+ /// for an SDR file and for a song or a still, neither of which is graded.
321+ content_light: ContentLight,
315322 /// Source 0's own picture, kept from the open: the project resolution
316323 /// starts here, and a caller offering sizes to pick from needs the media's
317324 /// own among them or a project moved off it could never come back.
@@ -585,8 +592,15 @@ impl PlaybackSession {
585592 // first edit -- and the range opened above is exactly that clip's.
586593 let project = Project::single(&path, meta.frame_count);
587594 let span = project.composite_span_at(0);
595+ // A second, header-only open purely for the light level: `open_worker`
596+ // above already read one to hand the decode thread its own, but never
597+ // hands it back out. The same trade the audio header cache above this
598+ // makes -- a second container open, paid once at open rather than never
599+ // -- since nothing here decodes a single picture.
600+ let content_light = Demuxer::open(&path).map(|(_, d)| d.light()).unwrap_or_default();
588601 Ok(Self {
589602 meta,
603+ content_light,
590604 native: (meta.width, meta.height),
591605 native_fps: meta.frame_rate,
592606 frames: stream.frames,
@@ -707,6 +721,7 @@ impl PlaybackSession {
707721 let stream = DecodeSession::open_black(width, height, span.map_or(1, |s| s.len));
708722 Ok(Self {
709723 meta,
724+ content_light: ContentLight::default(),
710725 native: (width, height),
711726 native_fps: frame_rate,
712727 frames: stream.frames,
@@ -803,6 +818,7 @@ impl PlaybackSession {
803818 )?;
804819 Ok(Self {
805820 meta,
821+ content_light: ContentLight::default(),
806822 native: (meta.width, meta.height),
807823 native_fps: IMAGE_ONLY_RATE,
808824 frames: stream.frames,
@@ -897,6 +913,15 @@ impl PlaybackSession {
897913 // ([`open_audio_only`](Self::open_audio_only)), and the placeholder
898914 // black stream is superseded by the `seek` at the end of this function
899915 // like every other worker opened here.
916+ // What source 0's own file declares about its light level, read the
917+ // same way [`open_stream`](Self::open_stream) reads it for a fresh
918+ // open: [`ContentLight::default()`] for a song or a still, neither of
919+ // which is graded.
920+ let content_light = if crate::is_audio(&first.path) || crate::is_image(&first.path) {
921+ ContentLight::default()
922+ } else {
923+ Demuxer::open(&first.path).map(|(_, d)| d.light()).unwrap_or_default()
924+ };
900925 let (mut meta, stream) = match crate::is_audio(&first.path) {
901926 true => {
902927 let (width, height, canvas_fps) = AUDIO_ONLY_CANVAS;
@@ -1109,6 +1134,7 @@ impl PlaybackSession {
11091134 };
11101135 let mut session = Self {
11111136 meta,
1137+ content_light,
11121138 native,
11131139 native_fps,
11141140 frames: stream.frames,
@@ -2716,6 +2742,15 @@ impl PlaybackSession {
27162742 self.project.tone()
27172743 }
27182744
2745+ /// What source 0's own file declared about how bright it gets
2746+ /// ([`ContentLight`]): a property of the film, read once at open, and
2747+ /// entirely absent (every field `None`) for an SDR file, a song or a
2748+ /// still. Read-only -- the number a file carries, never a project setting
2749+ /// a user can override, since nothing in [`Project`] holds one to persist.
2750+ pub fn content_light(&self) -> ContentLight {
2751+ self.content_light
2752+ }
2753+
27192754 /// Picks one. Rebuilds the **picture** where the playhead is, exactly as
27202755 /// [`set_resolution`](Self::set_resolution) does -- the frame on screen is
27212756 /// remapped at once, paused or playing, and the sound is not touched: a