diff --git a/Userland/Libraries/LibGfx/ICCProfile.cpp b/Userland/Libraries/LibGfx/ICCProfile.cpp index 72492006af..e8a4098563 100644 --- a/Userland/Libraries/LibGfx/ICCProfile.cpp +++ b/Userland/Libraries/LibGfx/ICCProfile.cpp @@ -233,6 +233,23 @@ ErrorOr parse_pcs_illuminant(ICCHeader const& header) return xyz; } + +Optional parse_profile_id(ICCHeader const& header) +{ + // ICC v4, 7.2.18 Profile ID field + // "A profile ID field value of zero (00h) shall indicate that a profile ID has not been calculated." + bool did_calculate_profile_id = false; + for (u8 b : header.profile_md5) + if (b != 0) + did_calculate_profile_id = true; + if (!did_calculate_profile_id) + return {}; + + Crypto::Hash::MD5::DigestType md5; + static_assert(sizeof(md5.data) == sizeof(header.profile_md5)); + memcpy(md5.data, header.profile_md5, sizeof(md5.data)); + return md5; +} } StringView device_class_name(DeviceClass device_class) @@ -364,6 +381,7 @@ ErrorOr> Profile::try_load_from_externally_owned_memory(R profile->m_flags = Flags { header.profile_flags }; profile->m_rendering_intent = TRY(parse_rendering_intent(header)); profile->m_pcs_illuminant = TRY(parse_pcs_illuminant(header)); + profile->m_id = parse_profile_id(header); return profile; } diff --git a/Userland/Libraries/LibGfx/ICCProfile.h b/Userland/Libraries/LibGfx/ICCProfile.h index d60601a779..65bcf61434 100644 --- a/Userland/Libraries/LibGfx/ICCProfile.h +++ b/Userland/Libraries/LibGfx/ICCProfile.h @@ -11,6 +11,7 @@ #include #include #include +#include namespace Gfx::ICC { @@ -136,6 +137,7 @@ public: Flags flags() const { return m_flags; } RenderingIntent rendering_intent() const { return m_rendering_intent; } const XYZ& pcs_illuminant() const { return m_pcs_illuminant; } + Optional const& id() const { return m_id; } private: Version m_version; @@ -146,6 +148,7 @@ private: Flags m_flags; RenderingIntent m_rendering_intent; XYZ m_pcs_illuminant; + Optional m_id; }; }