diff --git a/Userland/Applications/ImageViewer/ViewWidget.cpp b/Userland/Applications/ImageViewer/ViewWidget.cpp index b2f5c8545a..a6b761f35f 100644 --- a/Userland/Applications/ImageViewer/ViewWidget.cpp +++ b/Userland/Applications/ImageViewer/ViewWidget.cpp @@ -224,7 +224,7 @@ ErrorOr ViewWidget::try_open_file(String const& path, Core::File& file) Vector frames; // Note: Doing this check only requires reading the header of images // (so if the image is not vector graphics it can be still be decoded OOP). - if (auto decoder = Gfx::ImageDecoder::try_create_for_raw_bytes(file_data); decoder && decoder->is_vector()) { + if (auto decoder = Gfx::ImageDecoder::try_create_for_raw_bytes(file_data); decoder && decoder->natural_frame_format() == Gfx::NaturalFrameFormat::Vector) { // Use in-process decoding for vector graphics. is_animated = decoder->is_animated(); loop_count = decoder->loop_count(); diff --git a/Userland/Libraries/LibGfx/ImageFormats/ImageDecoder.h b/Userland/Libraries/LibGfx/ImageFormats/ImageDecoder.h index 55d08e04ca..aadc4ef74e 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/ImageDecoder.h +++ b/Userland/Libraries/LibGfx/ImageFormats/ImageDecoder.h @@ -28,6 +28,11 @@ struct VectorImageFrameDescriptor { int duration { 0 }; }; +enum class NaturalFrameFormat { + RGB, + Vector, +}; + class ImageDecoderPlugin { public: virtual ~ImageDecoderPlugin() = default; @@ -53,7 +58,7 @@ public: virtual ErrorOr frame(size_t index, Optional ideal_size = {}) = 0; virtual ErrorOr> icc_data() { return OptionalNone {}; } - virtual bool is_vector() { return false; } + virtual NaturalFrameFormat natural_frame_format() const { return NaturalFrameFormat::RGB; } virtual ErrorOr vector_frame(size_t) { VERIFY_NOT_REACHED(); } protected: @@ -75,7 +80,9 @@ public: ErrorOr frame(size_t index, Optional ideal_size = {}) const { return m_plugin->frame(index, ideal_size); } ErrorOr> icc_data() const { return m_plugin->icc_data(); } - bool is_vector() { return m_plugin->is_vector(); } + NaturalFrameFormat natural_frame_format() { return m_plugin->natural_frame_format(); } + + // Call only if natural_frame_format() == NaturalFrameFormat::Vector. ErrorOr vector_frame(size_t index) { return m_plugin->vector_frame(index); } private: diff --git a/Userland/Libraries/LibGfx/ImageFormats/TinyVGLoader.h b/Userland/Libraries/LibGfx/ImageFormats/TinyVGLoader.h index 76c49d9d10..5ea7a4aa52 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/TinyVGLoader.h +++ b/Userland/Libraries/LibGfx/ImageFormats/TinyVGLoader.h @@ -83,7 +83,7 @@ public: virtual IntSize size() override; virtual ErrorOr frame(size_t index, Optional ideal_size = {}) override; - virtual bool is_vector() override { return true; } + virtual NaturalFrameFormat natural_frame_format() const override { return NaturalFrameFormat::Vector; } virtual ErrorOr vector_frame(size_t index) override; virtual ~TinyVGImageDecoderPlugin() override = default;