diff options
author | Nico Weber <thakis@chromium.org> | 2023-01-04 14:55:16 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-01-05 10:54:35 +0100 |
commit | d5c8c90ff063f67cccc5c695ed2236fc036fb7b2 (patch) | |
tree | df028c09b554b92d301c19d11ba826001c9c3f32 /Userland/Libraries | |
parent | c10a02c40588e8c0d235d1ca3696c8a600023f90 (diff) | |
download | serenity-d5c8c90ff063f67cccc5c695ed2236fc036fb7b2.zip |
LibGfx: Store profile id MD5 in ICCProfile
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibGfx/ICCProfile.cpp | 18 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/ICCProfile.h | 3 |
2 files changed, 21 insertions, 0 deletions
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<XYZ> parse_pcs_illuminant(ICCHeader const& header) return xyz; } + +Optional<Crypto::Hash::MD5::DigestType> 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<NonnullRefPtr<Profile>> 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 <AK/NonnullRefPtr.h> #include <AK/RefCounted.h> #include <AK/Span.h> +#include <LibCrypto/Hash/MD5.h> 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<Crypto::Hash::MD5::DigestType> 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<Crypto::Hash::MD5::DigestType> m_id; }; } |