/* * Copyright (c) 2021, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include namespace Gfx { // Decoder for the "Quite OK Image" format (v1.0). // https://qoiformat.org/qoi-specification.pdf struct [[gnu::packed]] QOIHeader { char magic[4]; u32 width; u32 height; u8 channels; u8 colorspace; }; struct QOILoadingContext { enum class State { NotDecoded = 0, HeaderDecoded, ImageDecoded, Error, }; State state { State::NotDecoded }; OwnPtr stream {}; QOIHeader header {}; RefPtr bitmap; }; class QOIImageDecoderPlugin final : public ImageDecoderPlugin { public: static ErrorOr sniff(ReadonlyBytes); static ErrorOr> create(ReadonlyBytes); virtual ~QOIImageDecoderPlugin() override = default; virtual IntSize size() override; virtual void set_volatile() override; [[nodiscard]] virtual bool set_nonvolatile(bool& was_purged) 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; } virtual ErrorOr frame(size_t index) override; virtual ErrorOr> icc_data() override; private: ErrorOr decode_header_and_update_context(Stream&); ErrorOr decode_image_and_update_context(Stream&); QOIImageDecoderPlugin(NonnullOwnPtr); OwnPtr m_context; }; } template<> struct AK::Traits : public GenericTraits { static constexpr bool is_trivially_serializable() { return true; } };