Skip to content

Commit

Permalink
Fix XML generation after XML->RPU verification
Browse files Browse the repository at this point in the history
And add a test
  • Loading branch information
quietvoid committed Jan 7, 2022
1 parent f0fec15 commit 311934b
Show file tree
Hide file tree
Showing 4 changed files with 281 additions and 71 deletions.
110 changes: 110 additions & 0 deletions assets/tests/cmv4_0_2_custom_displays.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<DolbyLabsMDF xmlns="http://www.dolby.com/schemas/dvmd/4_0_2">
<Version>4.0.2</Version>
<RevisionHistory>
<Revision>
<DateTime>2020-02-17T11:29:59Z</DateTime>
<Author>Blackmagic Design</Author>
<Software>DaVinci Resolve Studio</Software>
<SoftwareVersion>16.1.2.026</SoftwareVersion>
</Revision>
</RevisionHistory>
<Outputs>
<Output>
<CompositionName>Black</CompositionName>
<UniqueID>118cbebe-317f-4d84-9b10-604289433563</UniqueID>
<NumberVideoTracks>1</NumberVideoTracks>
<CanvasAspectRatio>1.77778</CanvasAspectRatio>
<ImageAspectRatio>1.77778</ImageAspectRatio>
<Video>
<Track>
<TrackName>V1</TrackName>
<UniqueID>852c64bc-9b4c-4546-b013-a333f6a871ca</UniqueID>
<EditRate>24000 1001</EditRate>
<ColorEncoding>
<Primaries>
<Red>0.68 0.32</Red>
<Green>0.265 0.69</Green>
<Blue>0.15 0.06</Blue>
</Primaries>
<WhitePoint>0.3127 0.329</WhitePoint>
<PeakBrightness>10000</PeakBrightness>
<MinimumBrightness>0</MinimumBrightness>
<Encoding>pq</Encoding>
<ColorSpace>rgb</ColorSpace>
<SignalRange>computer</SignalRange>
</ColorEncoding>
<Level6 level="6">
<MaxCLL>0</MaxCLL>
<MaxFALL>0</MaxFALL>
</Level6>
<PluginNode>
<DVGlobalData level="0">
<MasteringDisplay>
<ID>255</ID>
<Name>1000-nit, P3, D65, ST.2084, Full</Name>
<Primaries>
<Red>0.681 0.322</Red>
<Green>0.2653 0.694</Green>
<Blue>0.155 0.066</Blue>
</Primaries>
<WhitePoint>0.31277 0.3298</WhitePoint>
<PeakBrightness>1000</PeakBrightness>
<MinimumBrightness>0.0001</MinimumBrightness>
<DiagonalSize>42</DiagonalSize>
</MasteringDisplay>
<TargetDisplay>
<ID>255</ID>
<Name>100-nit, BT.709, BT.1886, Full</Name>
<Primaries>
<Red>0.641 0.332</Red>
<Green>0.33 0.64</Green>
<Blue>0.155 0.066</Blue>
</Primaries>
<WhitePoint>0.31277 0.3298</WhitePoint>
<PeakBrightness>100</PeakBrightness>
<MinimumBrightness>0.005</MinimumBrightness>
<EOTF>gamma_bt1886</EOTF>
<DiagonalSize>42</DiagonalSize>
</TargetDisplay>
</DVGlobalData>
<Level254 level="254">
<DMMode>0</DMMode>
<DMVersion>2</DMVersion>
<CMVersion>4 0</CMVersion>
</Level254>
</PluginNode>
<Shot>
<UniqueID>07e96e28-5bd9-47ef-8e21-4bbac5986052</UniqueID>
<Record>
<In>86400</In>
<Duration>24</Duration>
</Record>
<PluginNode>
<DVDynamicData>
<Level1 level="1">
<ImageCharacter>0 0.2 0.508078</ImageCharacter>
</Level1>
<Level3 level="3">
<L1Offset>0 -0.2 -0.508078</L1Offset>
</Level3>
<Level8 level="8">
<TID>255</TID>
<L8Trim>0.01 0.02 0.03 0.04 0.05 0.06</L8Trim>
<MidContrastBias>0.02</MidContrastBias>
<HighlightClipping>-0.0180664</HighlightClipping>
<SaturationVectorField>0 0 0 0 0.17 0</SaturationVectorField>
<HueVectorField>0 0.25 0 0 0 0</HueVectorField>
</Level8>
<Level9 level="9">
<SourceColorModel>255</SourceColorModel>
<SourceColorPrimary>0.681 0.322 0.2653 0.694 0.155 0.066 0.31277 0.3298</SourceColorPrimary>
</Level9>
</DVDynamicData>
</PluginNode>
</Shot>
</Track>
</Video>
</Output>
</Outputs>
</DolbyLabsMDF>
8 changes: 4 additions & 4 deletions dolby_vision/src/rpu/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,8 @@ mod tests {

if let ExtMetadataBlock::Level3(level3) = shot3_vdr_dm_data.get_block(3).unwrap() {
assert_eq!(level3.min_pq_offset, 2048);
assert_eq!(level3.max_pq_offset, 1871);
assert_eq!(level3.avg_pq_offset, 2048);
assert_eq!(level3.max_pq_offset, 2048);
assert_eq!(level3.avg_pq_offset, 1871);
}

if let ExtMetadataBlock::Level5(level5) = shot3_vdr_dm_data.get_block(5).unwrap() {
Expand Down Expand Up @@ -519,8 +519,8 @@ mod tests {

if let ExtMetadataBlock::Level3(level3) = shot3_edit_vdr_dm_data.get_block(3).unwrap() {
assert_eq!(level3.min_pq_offset, 2048);
assert_eq!(level3.max_pq_offset, 1871);
assert_eq!(level3.avg_pq_offset, 2048);
assert_eq!(level3.max_pq_offset, 2048);
assert_eq!(level3.avg_pq_offset, 1871);
}

if let ExtMetadataBlock::Level5(level5) = shot3_edit_vdr_dm_data.get_block(5).unwrap() {
Expand Down
138 changes: 71 additions & 67 deletions dolby_vision/src/xml/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ impl CmXmlParser {
parser.config.shots.sort_by_key(|s| s.start);

// Add default L10 blocks
parser.parse_global_level10_targets()?;
if parser.is_cmv4() {
parser.parse_global_level10_targets()?;
}

parser.config.length = parser.config.shots.iter().map(|s| s.duration).sum();
} else {
Expand Down Expand Up @@ -230,7 +232,55 @@ impl CmXmlParser {
.parse::<u16>()
.unwrap();

if self.xml_version >= 0x500 {
let min_nits = target_node
.children()
.find(|e| e.has_tag_name("MinimumBrightness"))
.unwrap()
.text()
.unwrap()
.parse::<f64>()
.unwrap();

let primary_red = target_node
.descendants()
.find(|e| e.has_tag_name("Red"))
.unwrap()
.text()
.unwrap();

let primary_green = target_node
.descendants()
.find(|e| e.has_tag_name("Green"))
.unwrap()
.text()
.unwrap();

let primary_blue = target_node
.descendants()
.find(|e| e.has_tag_name("Blue"))
.unwrap()
.text()
.unwrap();

let primary_white = target_node
.children()
.find(|e| e.has_tag_name("WhitePoint"))
.unwrap()
.text()
.unwrap();

let primaries: Vec<f64> = [primary_red, primary_green, primary_blue, primary_white]
.join(&self.separator.to_string())
.split(self.separator)
.map(|v| v.parse::<f64>().unwrap())
.collect();

ensure!(
primaries.len() == 8,
"Primaries + WP should be a total of 8 values"
);

let include_target = if self.xml_version >= 0x500 {
let application_type = target_node
.children()
.find(|e| e.has_tag_name("ApplicationType"))
Expand All @@ -240,73 +290,19 @@ impl CmXmlParser {
.to_string();

// Only parse HOME targets
if application_type == "HOME" {
let min_nits = target_node
.children()
.find(|e| e.has_tag_name("MinimumBrightness"))
.unwrap()
.text()
.unwrap()
.parse::<f64>()
.unwrap();

let primary_red = target_node
.descendants()
.find(|e| e.has_tag_name("Red"))
.unwrap()
.text()
.unwrap();

let primary_green = target_node
.descendants()
.find(|e| e.has_tag_name("Green"))
.unwrap()
.text()
.unwrap();

let primary_blue = target_node
.descendants()
.find(|e| e.has_tag_name("Blue"))
.unwrap()
.text()
.unwrap();

let primary_white = target_node
.children()
.find(|e| e.has_tag_name("WhitePoint"))
.unwrap()
.text()
.unwrap();

let primaries: Vec<f64> =
[primary_red, primary_green, primary_blue, primary_white]
.join(&self.separator.to_string())
.split(self.separator)
.map(|v| v.parse::<f64>().unwrap())
.collect();

ensure!(
primaries.len() == 8,
"Primaries + WP should be a total of 8 values"
);

targets.insert(
id.clone(),
TargetDisplay {
id: id.clone(),
peak_nits,
min_nits,
primaries: primaries.try_into().unwrap(),
},
);
}
application_type == "HOME"
} else {
true
};

if include_target {
targets.insert(
id.clone(),
TargetDisplay {
id,
id: id.clone(),
peak_nits,
..Default::default()
min_nits,
primaries: primaries.try_into().unwrap(),
},
);
}
Expand Down Expand Up @@ -492,7 +488,10 @@ impl CmXmlParser {
for (id, target) in &self.target_displays {
let index = self.find_primary_index(&target.primaries, false)?;

let length = if index == 255 { 21 } else { 5 };

let mut block = ExtMetadataBlockLevel10 {
length,
target_display_index: target.id.parse::<u8>().unwrap(),
target_max_pq: min(
4095,
Expand Down Expand Up @@ -612,6 +611,8 @@ impl CmXmlParser {
.unwrap()
.text()
.unwrap();

// [min, avg, max]
let measurements: Vec<&str> = measurements.split(self.separator).collect();

ensure!(
Expand All @@ -622,9 +623,9 @@ impl CmXmlParser {
Ok(ExtMetadataBlockLevel3 {
min_pq_offset: ((measurements[0].parse::<f32>().unwrap() * 2048.0) + 2048.0).round()
as u16,
max_pq_offset: ((measurements[1].parse::<f32>().unwrap() * 2048.0) + 2048.0).round()
avg_pq_offset: ((measurements[1].parse::<f32>().unwrap() * 2048.0) + 2048.0).round()
as u16,
avg_pq_offset: ((measurements[2].parse::<f32>().unwrap() * 2048.0) + 2048.0).round()
max_pq_offset: ((measurements[2].parse::<f32>().unwrap() * 2048.0) + 2048.0).round()
as u16,
})
}
Expand Down Expand Up @@ -832,7 +833,7 @@ impl CmXmlParser {
if is_source {
primary_index
} else {
// TODO: Why are the target primaries offset by the preset source primaries?
// FIXME: Why are the target primaries offset by the preset source primaries?
primary_index + level9::PREDEFINED_COLORSPACE_PRIMARIES.len()
}
} else {
Expand Down Expand Up @@ -864,7 +865,10 @@ impl CmXmlParser {

let index = self.find_primary_index(&primaries, true)?;

let length = if index == 255 { 17 } else { 1 };

let mut block = ExtMetadataBlockLevel9 {
length,
source_primary_index: index,
..Default::default()
};
Expand Down
Loading

0 comments on commit 311934b

Please sign in to comment.