Skip to content

Commit

Permalink
Avoid overriding min_pq/max_pq when explicitly set by user
Browse files Browse the repository at this point in the history
  • Loading branch information
quietvoid committed Feb 19, 2024
1 parent 07a19d0 commit 13f32b3
Showing 1 changed file with 39 additions and 15 deletions.
54 changes: 39 additions & 15 deletions dolby_vision/src/rpu/vdr_dm_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ impl VdrDmData {
Ok(())
}

pub fn with_cmv29_dm_data(mut self) -> Self {
self.cmv29_metadata = Some(DmData::V29(CmV29DmData::default()));
self
}

pub fn extension_metadata_for_level(&self, level: u8) -> Option<&DmData> {
if CmV29DmData::ALLOWED_BLOCK_LEVELS.contains(&level) {
return self.cmv29_metadata.as_ref();
Expand Down Expand Up @@ -442,11 +447,11 @@ impl VdrDmData {
if let Some(ExtMetadataBlock::Level6(level6_block)) = self.get_block(6) {
let (derived_min_pq, derived_max_pq) = level6_block.source_meta_from_l6();

if self.source_min_pq == 0 {
if min_pq.is_none() && self.source_min_pq == 0 {
self.source_min_pq = derived_min_pq;
}

if self.source_max_pq == 0 {
if max_pq.is_none() && self.source_max_pq == 0 {
self.source_max_pq = derived_max_pq;
}
}
Expand All @@ -472,20 +477,14 @@ impl VdrDmData {
GenerateProfile::Profile5 => Profile5::dm_data(),
GenerateProfile::Profile81 => Profile81::dm_data(),
GenerateProfile::Profile84 => Profile84::dm_data(),
};

match config.cm_version {
CmVersion::V29 => {
vdr_dm_data.cmv29_metadata = Some(DmData::V29(CmV29DmData::default()))
}
CmVersion::V40 => {
vdr_dm_data.cmv29_metadata = Some(DmData::V29(CmV29DmData::default()));
}
.with_cmv29_dm_data();

vdr_dm_data.cmv40_metadata = if let Some(level254) = &config.level254 {
Some(DmData::V40(CmV40DmData::new_with_custom_l254(level254)))
} else {
Some(DmData::V40(CmV40DmData::new_with_l254_402()))
}
if config.cm_version == CmVersion::V40 {
vdr_dm_data.cmv40_metadata = if let Some(level254) = &config.level254 {
Some(DmData::V40(CmV40DmData::new_with_custom_l254(level254)))
} else {
Some(DmData::V40(CmV40DmData::new_with_l254_402()))
}
}

Expand Down Expand Up @@ -536,3 +535,28 @@ impl CmVersion {
CmVersion::V40
}
}

#[cfg(test)]
mod tests {
use crate::rpu::extension_metadata::blocks::{ExtMetadataBlock, ExtMetadataBlockLevel6};

use super::VdrDmData;

#[test]
fn change_source_levels_with_zero() {
let mut vdr_dm_data = VdrDmData::default_pq().with_cmv29_dm_data();
vdr_dm_data
.add_metadata_block(ExtMetadataBlock::Level6(ExtMetadataBlockLevel6 {
max_display_mastering_luminance: 1000,
min_display_mastering_luminance: 1,
max_content_light_level: 1000,
max_frame_average_light_level: 400,
}))
.unwrap();

vdr_dm_data.change_source_levels(Some(0), Some(1000));

assert_eq!(vdr_dm_data.source_min_pq, 0);
assert_eq!(vdr_dm_data.source_max_pq, 1000);
}
}

0 comments on commit 13f32b3

Please sign in to comment.