display_types/cea861/hdr.rs
1bitflags::bitflags! {
2 /// Electro-Optical Transfer Functions (EOTFs) supported by the display,
3 /// from the HDR Static Metadata Data Block (extended tag `0x06`).
4 #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
6 pub struct HdrEotf: u8 {
7 /// Traditional gamma — SDR luminance range.
8 const SDR = 0x01;
9 /// Traditional gamma — HDR luminance range.
10 const HDR = 0x02;
11 /// SMPTE ST 2084 (PQ / HDR10).
12 const ST2084 = 0x04;
13 /// Hybrid Log-Gamma (HLG).
14 const HLG = 0x08;
15 }
16}
17
18/// Decoded HDR Static Metadata Data Block (extended tag `0x06`).
19#[non_exhaustive]
20#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
21#[derive(Debug, Clone, PartialEq)] // no Eq: contains f32
22pub struct HdrStaticMetadata {
23 /// Supported EOTFs (tone-mapping curves).
24 pub eotf: HdrEotf,
25 /// Static Metadata Descriptor type bitmap (usually bit 0 = Type 1 / MaxCLL/MaxFALL).
26 pub static_metadata_descriptors: u8,
27 /// Desired content maximum luminance in cd/m², decoded from byte 3.
28 ///
29 /// Encoded as `50 × 2^(raw / 32)`. `None` when the byte is absent.
30 pub max_luminance: Option<f32>,
31 /// Desired content maximum frame-average light level (MaxFALL) in cd/m².
32 ///
33 /// Same encoding as `max_luminance`. `None` when absent.
34 pub max_fall: Option<f32>,
35 /// Desired content minimum luminance in cd/m², decoded from byte 5.
36 ///
37 /// Encoded as `max_luminance × (raw / 255)² / 100`. `None` when absent or when
38 /// `max_luminance` is not present.
39 pub min_luminance: Option<f32>,
40}
41
42/// One entry from an HDR Dynamic Metadata Data Block (extended tag `0x07`).
43///
44/// Each descriptor identifies the HDR dynamic metadata technology supported
45/// (e.g. HDR10+ / SMPTE ST 2094, or Dolby Vision).
46#[non_exhaustive]
47#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
48#[derive(Debug, Clone, Copy, PartialEq, Eq)]
49pub struct HdrDynamicMetadataDescriptor {
50 /// Application type identifier (bits 5–0 of the descriptor byte).
51 ///
52 /// `1` = SMPTE ST 2094 (HDR10+); `2` = Dolby Vision.
53 pub application_type: u8,
54 /// Application metadata version (bits 7–6 of the descriptor byte).
55 pub application_version: u8,
56}
57
58impl HdrDynamicMetadataDescriptor {
59 /// Constructs an `HdrDynamicMetadataDescriptor`.
60 pub fn new(application_type: u8, application_version: u8) -> Self {
61 Self {
62 application_type,
63 application_version,
64 }
65 }
66}
67
68impl HdrStaticMetadata {
69 /// Constructs an `HdrStaticMetadata`.
70 #[allow(clippy::too_many_arguments)]
71 pub fn new(
72 eotf: HdrEotf,
73 static_metadata_descriptors: u8,
74 max_luminance: Option<f32>,
75 max_fall: Option<f32>,
76 min_luminance: Option<f32>,
77 ) -> Self {
78 Self {
79 eotf,
80 static_metadata_descriptors,
81 max_luminance,
82 max_fall,
83 min_luminance,
84 }
85 }
86}