diff options
author | Liav A <liavalb@gmail.com> | 2023-01-20 10:13:14 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-01-20 15:13:31 +0000 |
commit | 57e19a7e56a7684ce78e7660bda9fc1f5d9d16f3 (patch) | |
tree | d8e4846109693dadc43db559ecba2e8f0cf9ffa8 /Userland/Libraries/LibGfx/QOILoader.h | |
parent | 6e6999ce5767121a6904b6c36454723e39b9bf24 (diff) | |
download | serenity-57e19a7e56a7684ce78e7660bda9fc1f5d9d16f3.zip |
LibGfx: Re-structure the whole initialization pattern for image decoders
When trying to figure out the correct implementation, we now have a very
strong distinction on plugins that are well suited for sniffing, and
plugins that need a MIME type to be chosen.
Instead of having multiple calls to non-static virtual sniff methods for
each Image decoding plugin, we have 2 static methods for each
implementation:
1. The sniff method, which in contrast to the old method, gets a
ReadonlyBytes parameter and ensures we can figure out the result
with zero heap allocations for most implementations.
2. The create method, which just creates a new instance so we don't
expose the constructor to everyone anymore.
In addition to that, we have a new virtual method called initialize,
which has a per-implementation initialization pattern to actually ensure
each implementation can construct a decoder object, and then have a
correct context being applied to it for the actual decoding.
Diffstat (limited to 'Userland/Libraries/LibGfx/QOILoader.h')
-rw-r--r-- | Userland/Libraries/LibGfx/QOILoader.h | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Userland/Libraries/LibGfx/QOILoader.h b/Userland/Libraries/LibGfx/QOILoader.h index 9446e69a16..b5df791830 100644 --- a/Userland/Libraries/LibGfx/QOILoader.h +++ b/Userland/Libraries/LibGfx/QOILoader.h @@ -40,13 +40,15 @@ struct QOILoadingContext { class QOIImageDecoderPlugin final : public ImageDecoderPlugin { public: + static ErrorOr<bool> sniff(ReadonlyBytes); + static ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> create(ReadonlyBytes); + virtual ~QOIImageDecoderPlugin() override = default; - QOIImageDecoderPlugin(u8 const*, size_t); virtual IntSize size() override; virtual void set_volatile() override; [[nodiscard]] virtual bool set_nonvolatile(bool& was_purged) override; - virtual bool sniff() override; + virtual bool initialize() override; virtual bool is_animated() override { return false; } virtual size_t loop_count() override { return 0; } virtual size_t frame_count() override { return 1; } @@ -56,6 +58,8 @@ private: ErrorOr<void> decode_header_and_update_context(InputMemoryStream&); ErrorOr<void> decode_image_and_update_context(InputMemoryStream&); + QOIImageDecoderPlugin(u8 const*, size_t); + OwnPtr<QOILoadingContext> m_context; }; |