Skip to content

Commit 10a08d0

Browse files
committed
rpu_info - use ExtMetadataBlockLevel2 instead of L2Data & extend MasteringDisplayPrimaries
(cherry picked from commit 86c28b1)
1 parent c8b27ad commit 10a08d0

File tree

3 files changed

+66
-60
lines changed

3 files changed

+66
-60
lines changed

dolby_vision/src/rpu/extension_metadata/primaries.rs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,40 @@ pub enum MasteringDisplayPrimaries {
5050
SGamut3Cine,
5151
}
5252

53-
impl MasteringDisplayPrimaries {
54-
pub fn u8_to_alias(value: u8) -> Option<&'static str> {
53+
impl From<u8> for MasteringDisplayPrimaries {
54+
fn from(value: u8) -> Self {
5555
match value {
56-
0 => Some("DCI-P3 D65"),
57-
1 => Some("BT.709"),
58-
2 => Some("BT.2020"),
59-
3 => Some("SMPTE-C"),
60-
4 => Some("BT.601"),
61-
5 => Some("DCI-P3"),
62-
6 => Some("ACES"),
63-
7 => Some("S-Gamut"),
64-
8 => Some("S-Gamut-3.Cine"),
65-
_ => None,
56+
0 => Self::DCIP3D65,
57+
1 => Self::BT709,
58+
2 => Self::BT2020,
59+
3 => Self::SMPTEC,
60+
4 => Self::BT601,
61+
5 => Self::DCIP3,
62+
6 => Self::ACES,
63+
7 => Self::SGamut,
64+
8 => Self::SGamut3Cine,
65+
_ => Self::DCIP3D65,
6666
}
6767
}
6868
}
6969

70+
impl std::fmt::Display for MasteringDisplayPrimaries {
71+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
72+
let alias = match self {
73+
Self::DCIP3D65 => "DCI-P3 D65",
74+
Self::BT709 => "BT.709",
75+
Self::BT2020 => "BT.2020",
76+
Self::SMPTEC => "SMPTE-C",
77+
Self::BT601 => "BT.601",
78+
Self::DCIP3 => "DCI-P3",
79+
Self::ACES => "ACES",
80+
Self::SGamut => "S-Gamut",
81+
Self::SGamut3Cine => "S-Gamut-3.Cine",
82+
};
83+
write!(f, "{}", alias)
84+
}
85+
}
86+
7087
impl ColorPrimaries {
7188
pub fn from_array_int(primaries: &[u16; 8]) -> ColorPrimaries {
7289
Self {

src/dovi/plotter.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ use std::path::PathBuf;
66
use anyhow::bail;
77

88
use anyhow::Result;
9+
use dolby_vision::rpu::extension_metadata::blocks::ExtMetadataBlockLevel2;
10+
use dolby_vision::rpu::utils::parse_rpu_file;
11+
use dolby_vision::utils::{nits_to_pq, pq_to_nits};
912
use plotters::coord::ranged1d::{KeyPointHint, NoDefaultFormatting, Ranged, ValueFormatter};
1013
use plotters::coord::types::RangedCoordusize;
1114
use plotters::prelude::{
@@ -14,11 +17,8 @@ use plotters::prelude::{
1417
};
1518
use plotters::style::{BLACK, Color, IntoTextStyle, RGBColor, ShapeStyle};
1619

17-
use dolby_vision::rpu::utils::parse_rpu_file;
18-
use dolby_vision::utils::{nits_to_pq, pq_to_nits};
19-
2020
use super::input_from_either;
21-
use super::rpu_info::{L2Data, RpusListSummary};
21+
use super::rpu_info::RpusListSummary;
2222
use crate::commands::PlotArgs;
2323

2424
#[cfg(not(feature = "system-font"))]
@@ -270,41 +270,46 @@ impl Plotter {
270270
let data = summary.l2_data.as_ref().unwrap();
271271
let l2_stats = summary.l2_stats.as_ref().unwrap();
272272

273-
type Series = (&'static str, fn(&L2Data) -> f64, (f64, f64, f64), RGBColor);
273+
type Series = (
274+
&'static str,
275+
fn(&ExtMetadataBlockLevel2) -> f64,
276+
(f64, f64, f64),
277+
RGBColor,
278+
);
274279
let series: [Series; 6] = [
275280
(
276281
"slope (gain)",
277-
|e| e.0 as f64,
282+
|e| e.trim_slope as f64,
278283
l2_stats.slope,
279284
RGBColor(96, 158, 232), // blue
280285
),
281286
(
282287
"offset (lift)",
283-
|e| e.1 as f64,
288+
|e| e.trim_offset as f64,
284289
l2_stats.offset,
285290
RGBColor(230, 110, 132), // pink
286291
),
287292
(
288293
"power (gamma)",
289-
|e| e.2 as f64,
294+
|e| e.trim_power as f64,
290295
l2_stats.power,
291296
RGBColor(236, 162, 75), // orange
292297
),
293298
(
294299
"chroma (weight)",
295-
|e| e.3 as f64,
300+
|e| e.trim_chroma_weight as f64,
296301
l2_stats.chroma,
297302
RGBColor(115, 187, 190), // cyan
298303
),
299304
(
300305
"saturation (gain)",
301-
|e| e.4 as f64,
306+
|e| e.trim_saturation_gain as f64,
302307
l2_stats.saturation,
303308
RGBColor(144, 106, 252), // purple
304309
),
305310
(
306311
"ms (weight)",
307-
|e| e.5 as f64,
312+
|e| e.ms_weight as f64,
308313
l2_stats.ms_weight,
309314
RGBColor(243, 205, 95), // yellow
310315
),

src/dovi/rpu_info.rs

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ use itertools::Itertools;
1717
use super::input_from_either;
1818
use crate::commands::InfoArgs;
1919

20-
pub type L2Data = (u16, u16, u16, u16, u16, i16);
21-
2220
pub struct RpuInfo {
2321
input: PathBuf,
2422
}
@@ -38,7 +36,7 @@ pub struct RpusListSummary {
3836
pub l1_data: Vec<(f64, f64, f64)>,
3937
pub l1_stats: SummaryL1Stats,
4038
pub l2_trims: Vec<String>,
41-
pub l2_data: Option<Vec<L2Data>>,
39+
pub l2_data: Option<Vec<ExtMetadataBlockLevel2>>,
4240
pub l2_stats: Option<SummaryL2Stats>,
4341
}
4442

@@ -443,14 +441,13 @@ impl RpusListSummary {
443441
})
444442
.into_iter()
445443
.sorted_by_key(|e| e.0)
446-
.filter_map(|(idx, frames)| {
447-
MasteringDisplayPrimaries::u8_to_alias(idx).map(|alias| {
448-
if frames < dmv2_count {
449-
format!("{alias} ({frames})")
450-
} else {
451-
alias.to_string()
452-
}
453-
})
444+
.map(|(idx, frames)| {
445+
let alias = MasteringDisplayPrimaries::from(idx).to_string();
446+
if frames < dmv2_count {
447+
format!("{alias} ({frames})")
448+
} else {
449+
alias
450+
}
454451
})
455452
.collect();
456453

@@ -481,35 +478,22 @@ impl RpusListSummary {
481478
pub fn with_l2_data(rpus: &[DoviRpu]) -> Result<Self> {
482479
let mut summary = Self::new(rpus)?;
483480

484-
let default_l2_for_missing = ExtMetadataBlock::Level2(ExtMetadataBlockLevel2::default());
485-
486481
let l2_data: Vec<_> = rpus
487482
.iter()
488483
.map(|rpu| {
489-
let block = rpu
490-
.vdr_dm_data
491-
.as_ref()
492-
.and_then(|dm| dm.get_block(2))
493-
.unwrap_or(&default_l2_for_missing);
494-
495-
if let ExtMetadataBlock::Level2(l2) = block {
496-
(
497-
l2.trim_slope,
498-
l2.trim_offset,
499-
l2.trim_power,
500-
l2.trim_chroma_weight,
501-
l2.trim_saturation_gain,
502-
l2.ms_weight,
503-
)
484+
if let Some(ExtMetadataBlock::Level2(l2)) =
485+
rpu.vdr_dm_data.as_ref().and_then(|dm| dm.get_block(2))
486+
{
487+
l2.clone()
504488
} else {
505-
unreachable!();
489+
ExtMetadataBlockLevel2::default()
506490
}
507491
})
508492
.collect();
509493

510-
fn min_max_avg<F>(data: &[L2Data], field_extractor: F) -> (f64, f64, f64)
494+
fn min_max_avg<F>(data: &[ExtMetadataBlockLevel2], field_extractor: F) -> (f64, f64, f64)
511495
where
512-
F: Fn(&L2Data) -> f64,
496+
F: Fn(&ExtMetadataBlockLevel2) -> f64,
513497
{
514498
let mut iter = data.iter().map(field_extractor);
515499
let first = iter.next().unwrap();
@@ -529,12 +513,12 @@ impl RpusListSummary {
529513
}
530514

531515
summary.l2_stats = Some(SummaryL2Stats {
532-
slope: min_max_avg(&l2_data, |e| e.0 as f64),
533-
offset: min_max_avg(&l2_data, |e| e.1 as f64),
534-
power: min_max_avg(&l2_data, |e| e.2 as f64),
535-
chroma: min_max_avg(&l2_data, |e| e.3 as f64),
536-
saturation: min_max_avg(&l2_data, |e| e.4 as f64),
537-
ms_weight: min_max_avg(&l2_data, |e| e.5 as f64),
516+
slope: min_max_avg(&l2_data, |e| e.trim_slope as f64),
517+
offset: min_max_avg(&l2_data, |e| e.trim_offset as f64),
518+
power: min_max_avg(&l2_data, |e| e.trim_power as f64),
519+
chroma: min_max_avg(&l2_data, |e| e.trim_chroma_weight as f64),
520+
saturation: min_max_avg(&l2_data, |e| e.trim_saturation_gain as f64),
521+
ms_weight: min_max_avg(&l2_data, |e| e.ms_weight as f64),
538522
});
539523
summary.l2_data = Some(l2_data);
540524

0 commit comments

Comments
 (0)