diff --git a/Userland/Libraries/LibGfx/ICC/Profile.cpp b/Userland/Libraries/LibGfx/ICC/Profile.cpp index 22e5161765..b9a6f3398d 100644 --- a/Userland/Libraries/LibGfx/ICC/Profile.cpp +++ b/Userland/Libraries/LibGfx/ICC/Profile.cpp @@ -1709,4 +1709,40 @@ XYZ const& Profile::red_matrix_column() const { return xyz_data(redMatrixColumnT XYZ const& Profile::green_matrix_column() const { return xyz_data(greenMatrixColumnTag); } XYZ const& Profile::blue_matrix_column() const { return xyz_data(blueMatrixColumnTag); } +Optional Profile::tag_string_data(TagSignature signature) const +{ + auto maybe_tag_data = tag_data(signature); + if (!maybe_tag_data.has_value()) + return {}; + auto& tag_data = maybe_tag_data.release_value(); + if (tag_data.type() == Gfx::ICC::MultiLocalizedUnicodeTagData::Type) { + auto& multi_localized_unicode = static_cast(tag_data); + // Try to find 'en-US', otherwise any 'en' language, otherwise the first record. + Optional en_string; + constexpr u16 language_en = ('e' << 8) + 'n'; + constexpr u16 country_us = ('U' << 8) + 'S'; + for (auto const& record : multi_localized_unicode.records()) { + if (record.iso_639_1_language_code == language_en) { + if (record.iso_3166_1_country_code == country_us) + return record.text; + en_string = record.text; + } + } + if (en_string.has_value()) + return en_string.value(); + if (!multi_localized_unicode.records().is_empty()) + return multi_localized_unicode.records().first().text; + return {}; + } + if (tag_data.type() == Gfx::ICC::TextDescriptionTagData::Type) { + auto& text_description = static_cast(tag_data); + return text_description.ascii_description(); + } + if (tag_data.type() == Gfx::ICC::TextTagData::Type) { + auto& text = static_cast(tag_data); + return text.text(); + } + return {}; +} + } diff --git a/Userland/Libraries/LibGfx/ICC/Profile.h b/Userland/Libraries/LibGfx/ICC/Profile.h index dd1053db8d..b91c7f2322 100644 --- a/Userland/Libraries/LibGfx/ICC/Profile.h +++ b/Userland/Libraries/LibGfx/ICC/Profile.h @@ -259,6 +259,8 @@ public: return m_tag_table.get(signature).map([](auto it) -> TagData const& { return *it; }); } + Optional tag_string_data(TagSignature signature) const; + size_t tag_count() const { return m_tag_table.size(); } // Only versions 2 and 4 are in use.