From 8f415e7b219b2527c3d9493ee12ebe8adeadc1fa Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Mon, 27 Feb 2023 08:37:05 -0500 Subject: LibGfx: Introduce ICC::Profile::create This can be used to programmatically create ICC::Profile objects. --- Userland/Libraries/LibGfx/ICC/Profile.cpp | 7 ++++++- Userland/Libraries/LibGfx/ICC/Profile.h | 13 +++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) (limited to 'Userland/Libraries') diff --git a/Userland/Libraries/LibGfx/ICC/Profile.cpp b/Userland/Libraries/LibGfx/ICC/Profile.cpp index f0afe9c7b9..1f13d43e43 100644 --- a/Userland/Libraries/LibGfx/ICC/Profile.cpp +++ b/Userland/Libraries/LibGfx/ICC/Profile.cpp @@ -1316,7 +1316,12 @@ ErrorOr> Profile::try_load_from_externally_owned_memory(R bytes = bytes.trim(header.on_disk_size); auto tag_table = TRY(read_tag_table(bytes)); - auto profile = TRY(try_make_ref_counted(header, move(tag_table))); + return create(header, move(tag_table)); +} + +ErrorOr> Profile::create(ProfileHeader const& header, OrderedHashMap> tag_table) +{ + auto profile = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) Profile(header, move(tag_table)))); TRY(profile->check_required_tags()); TRY(profile->check_tag_types()); diff --git a/Userland/Libraries/LibGfx/ICC/Profile.h b/Userland/Libraries/LibGfx/ICC/Profile.h index f4ddc6e4cc..709fd97423 100644 --- a/Userland/Libraries/LibGfx/ICC/Profile.h +++ b/Userland/Libraries/LibGfx/ICC/Profile.h @@ -211,12 +211,7 @@ struct ProfileHeader { class Profile : public RefCounted { public: static ErrorOr> try_load_from_externally_owned_memory(ReadonlyBytes); - - Profile(ProfileHeader const& header, OrderedHashMap> tag_table) - : m_header(header) - , m_tag_table(move(tag_table)) - { - } + static ErrorOr> create(ProfileHeader const& header, OrderedHashMap> tag_table); Optional preferred_cmm_type() const { return m_header.preferred_cmm_type; } Version version() const { return m_header.version; } @@ -262,6 +257,12 @@ public: bool is_v4() const { return version().major_version() == 4; } private: + Profile(ProfileHeader const& header, OrderedHashMap> tag_table) + : m_header(header) + , m_tag_table(move(tag_table)) + { + } + ErrorOr check_required_tags(); ErrorOr check_tag_types(); -- cgit v1.2.3