22 std::uint32_t flags {};
23 std::uint32_t colorspace {};
24 std::uint32_t metadata_type {};
26 std::uint8_t descriptor_type {};
29 std::uint16_t x {}, y {};
30 } primaries[3], white_point;
32 std::uint16_t max_luminance {};
33 std::uint16_t min_luminance {};
34 std::uint16_t max_cll {};
35 std::uint16_t max_fall {};
36 std::uint16_t padding {};
37 std::uint32_t reserved[2] {};
40 return flags & color_valid;
44 return known() && (flags & color_hdr_valid) && eotf == 2 &&
45 colorspace == colorspace_bt2020_rgb;
48 bool supported()
const {
49 if (!known() || (flags & ~(color_valid | color_hdr_valid | color_rgb_full_range)) || !(flags & color_rgb_full_range) || padding || reserved[0] || reserved[1]) {
52 if (colorspace != colorspace_default && colorspace != colorspace_bt2020_rgb) {
55 if (!(flags & color_hdr_valid)) {
56 const color_t zero {};
57 return std::memcmp(&metadata_type, &zero.metadata_type, offsetof(color_t, reserved) - offsetof(color_t, metadata_type)) == 0;
59 return metadata_type == 0 && descriptor_type == 0 &&
60 (eotf == 0 || (eotf == 2 && colorspace == colorspace_bt2020_rgb));
63 bool operator==(
const color_t &other)
const {
64 return std::memcmp(
this, &other,
sizeof(*
this)) == 0;
67 template<
class Metadata>
68 bool copy_hdr_metadata(Metadata &out)
const {
70 if (!supported() || !pq()) {
73 for (
int i = 0; i < 3; ++i) {
74 out.displayPrimaries[i].x = primaries[i].x;
75 out.displayPrimaries[i].y = primaries[i].y;
77 out.whitePoint.x = white_point.x;
78 out.whitePoint.y = white_point.y;
79 out.maxDisplayLuminance = max_luminance;
80 out.minDisplayLuminance = min_luminance;
81 out.maxContentLightLevel = max_cll;
82 out.maxFrameAverageLightLevel = max_fall;