From e3f976f17a04ea36d15fed2ec7fece02e5f1e779 Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Thu, 28 Dec 2023 18:58:45 -0500 Subject: [PATCH] LibGfx: Add an API to retrieve metadata from images All the data is passed using the `Metadata` object, which has a `main_tags` method. This method should be used when displaying only a few main tags, for example to fill the property window of a file manager. Another method returning the entire list of tags will be implemented later on. --- .../LibGfx/ImageFormats/ImageDecoder.h | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Userland/Libraries/LibGfx/ImageFormats/ImageDecoder.h b/Userland/Libraries/LibGfx/ImageFormats/ImageDecoder.h index 7f4ff02ecc..67b511df33 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/ImageDecoder.h +++ b/Userland/Libraries/LibGfx/ImageFormats/ImageDecoder.h @@ -7,9 +7,11 @@ #pragma once #include +#include #include #include #include +#include #include #include #include @@ -29,6 +31,28 @@ struct VectorImageFrameDescriptor { int duration { 0 }; }; +class Metadata { +public: + Metadata() = default; + virtual ~Metadata() = default; + + HashMap const& main_tags() const + { + if (m_main_tags.is_empty()) + fill_main_tags(); + + // This is designed to be used in a general GUI, don't include too much information here. + VERIFY(m_main_tags.size() < 8); + + return m_main_tags; + } + +protected: + virtual void fill_main_tags() const {}; + + mutable HashMap m_main_tags; +}; + enum class NaturalFrameFormat { RGB, Grayscale, @@ -59,6 +83,9 @@ public: virtual size_t first_animated_frame_index() { return 0; } virtual ErrorOr frame(size_t index, Optional ideal_size = {}) = 0; + + virtual Optional metadata() { return OptionalNone {}; } + virtual ErrorOr> icc_data() { return OptionalNone {}; } virtual NaturalFrameFormat natural_frame_format() const { return NaturalFrameFormat::RGB; } @@ -81,7 +108,10 @@ public: size_t loop_count() const { return m_plugin->loop_count(); } size_t frame_count() const { return m_plugin->frame_count(); } size_t first_animated_frame_index() const { return m_plugin->first_animated_frame_index(); } + ErrorOr frame(size_t index, Optional ideal_size = {}) const { return m_plugin->frame(index, ideal_size); } + + Optional metadata() const { return m_plugin->metadata(); } ErrorOr> icc_data() const { return m_plugin->icc_data(); } NaturalFrameFormat natural_frame_format() { return m_plugin->natural_frame_format(); }