summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-07-27 01:29:50 +0200
committerAndreas Kling <kling@serenityos.org>2021-07-27 01:29:50 +0200
commit751cb094ff5f2752cca3629f951bd9e99efc77f4 (patch)
treed80f67f92e34ed560fe82228817e5d1f15c7006c /Userland
parentd01b4327fabeabe77a3e57ab5d8a7dfb82eb3c52 (diff)
downloadserenity-751cb094ff5f2752cca3629f951bd9e99efc77f4.zip
LibGfx: Remove Gfx::ImageDecoder::bitmap() in favor of frame(index)
To transparently support multi-frame images, all decoder plugins have already been updated to return their only bitmap for frame(0). This patch completes the remaining cleanup work by removing the ImageDecoder::bitmap() API and having all clients call frame() instead.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibGUI/ImageWidget.cpp3
-rw-r--r--Userland/Libraries/LibGfx/BMPLoader.cpp5
-rw-r--r--Userland/Libraries/LibGfx/DDSLoader.cpp6
-rw-r--r--Userland/Libraries/LibGfx/ICOLoader.cpp7
-rw-r--r--Userland/Libraries/LibGfx/ImageDecoder.cpp5
-rw-r--r--Userland/Libraries/LibGfx/ImageDecoder.h4
-rw-r--r--Userland/Libraries/LibGfx/JPGLoader.cpp8
-rw-r--r--Userland/Libraries/LibGfx/PBMLoader.cpp8
-rw-r--r--Userland/Libraries/LibGfx/PGMLoader.cpp8
-rw-r--r--Userland/Libraries/LibGfx/PNGLoader.cpp7
-rw-r--r--Userland/Libraries/LibGfx/PPMLoader.cpp8
-rw-r--r--Userland/Libraries/LibWeb/Loader/FrameLoader.cpp6
-rw-r--r--Userland/Services/ImageDecoder/ClientConnection.cpp9
13 files changed, 35 insertions, 49 deletions
diff --git a/Userland/Libraries/LibGUI/ImageWidget.cpp b/Userland/Libraries/LibGUI/ImageWidget.cpp
index 887fe2938d..71e05e87bc 100644
--- a/Userland/Libraries/LibGUI/ImageWidget.cpp
+++ b/Userland/Libraries/LibGUI/ImageWidget.cpp
@@ -81,7 +81,8 @@ void ImageWidget::load_from_file(const StringView& path)
m_image_decoder = Gfx::ImageDecoder::try_create(mapped_file.bytes());
VERIFY(m_image_decoder);
- auto bitmap = m_image_decoder->bitmap();
+ auto frame = m_image_decoder->frame(0);
+ auto bitmap = frame.image;
VERIFY(bitmap);
set_bitmap(bitmap);
diff --git a/Userland/Libraries/LibGfx/BMPLoader.cpp b/Userland/Libraries/LibGfx/BMPLoader.cpp
index 69f8623a52..16837ceaf2 100644
--- a/Userland/Libraries/LibGfx/BMPLoader.cpp
+++ b/Userland/Libraries/LibGfx/BMPLoader.cpp
@@ -1397,7 +1397,8 @@ size_t BMPImageDecoderPlugin::frame_count()
ImageFrameDescriptor BMPImageDecoderPlugin::frame(size_t i)
{
if (i > 0)
- return { bitmap(), 0 };
- return {};
+ return {};
+ return { bitmap(), 0 };
}
+
}
diff --git a/Userland/Libraries/LibGfx/DDSLoader.cpp b/Userland/Libraries/LibGfx/DDSLoader.cpp
index 7289ed974b..5bf294919e 100644
--- a/Userland/Libraries/LibGfx/DDSLoader.cpp
+++ b/Userland/Libraries/LibGfx/DDSLoader.cpp
@@ -1046,9 +1046,11 @@ size_t DDSImageDecoderPlugin::frame_count()
return 1;
}
-ImageFrameDescriptor DDSImageDecoderPlugin::frame([[maybe_unused]] size_t i)
+ImageFrameDescriptor DDSImageDecoderPlugin::frame(size_t i)
{
- // We have "frames", but they are all the same image, so lets just use the largest version.
+ if (i > 0)
+ return {};
return { bitmap(), 0 };
}
+
}
diff --git a/Userland/Libraries/LibGfx/ICOLoader.cpp b/Userland/Libraries/LibGfx/ICOLoader.cpp
index 969117e938..fe151c006f 100644
--- a/Userland/Libraries/LibGfx/ICOLoader.cpp
+++ b/Userland/Libraries/LibGfx/ICOLoader.cpp
@@ -382,10 +382,9 @@ size_t ICOImageDecoderPlugin::frame_count()
ImageFrameDescriptor ICOImageDecoderPlugin::frame(size_t i)
{
- if (i > 0) {
- return { bitmap(), 0 };
- }
- return {};
+ if (i > 0)
+ return {};
+ return { bitmap(), 0 };
}
}
diff --git a/Userland/Libraries/LibGfx/ImageDecoder.cpp b/Userland/Libraries/LibGfx/ImageDecoder.cpp
index 2d7f89554e..40ccb2bc85 100644
--- a/Userland/Libraries/LibGfx/ImageDecoder.cpp
+++ b/Userland/Libraries/LibGfx/ImageDecoder.cpp
@@ -78,9 +78,4 @@ ImageDecoder::~ImageDecoder()
{
}
-RefPtr<Gfx::Bitmap> ImageDecoder::bitmap() const
-{
- return m_plugin->bitmap();
-}
-
}
diff --git a/Userland/Libraries/LibGfx/ImageDecoder.h b/Userland/Libraries/LibGfx/ImageDecoder.h
index 964cdee23f..d3c8272b83 100644
--- a/Userland/Libraries/LibGfx/ImageDecoder.h
+++ b/Userland/Libraries/LibGfx/ImageDecoder.h
@@ -30,7 +30,6 @@ public:
virtual ~ImageDecoderPlugin() { }
virtual IntSize size() = 0;
- virtual RefPtr<Gfx::Bitmap> bitmap() = 0;
virtual void set_volatile() = 0;
[[nodiscard]] virtual bool set_nonvolatile(bool& was_purged) = 0;
@@ -43,6 +42,8 @@ public:
virtual ImageFrameDescriptor frame(size_t i) = 0;
protected:
+ virtual RefPtr<Gfx::Bitmap> bitmap() = 0;
+
ImageDecoderPlugin() { }
};
@@ -54,7 +55,6 @@ public:
IntSize size() const { return m_plugin->size(); }
int width() const { return size().width(); }
int height() const { return size().height(); }
- RefPtr<Gfx::Bitmap> bitmap() const;
void set_volatile() { m_plugin->set_volatile(); }
[[nodiscard]] bool set_nonvolatile(bool& was_purged) { return m_plugin->set_nonvolatile(was_purged); }
bool sniff() const { return m_plugin->sniff(); }
diff --git a/Userland/Libraries/LibGfx/JPGLoader.cpp b/Userland/Libraries/LibGfx/JPGLoader.cpp
index 3d424a28ab..0169e03316 100644
--- a/Userland/Libraries/LibGfx/JPGLoader.cpp
+++ b/Userland/Libraries/LibGfx/JPGLoader.cpp
@@ -1327,9 +1327,9 @@ size_t JPGImageDecoderPlugin::frame_count()
ImageFrameDescriptor JPGImageDecoderPlugin::frame(size_t i)
{
- if (i > 0) {
- return { bitmap(), 0 };
- }
- return {};
+ if (i > 0)
+ return {};
+ return { bitmap(), 0 };
}
+
}
diff --git a/Userland/Libraries/LibGfx/PBMLoader.cpp b/Userland/Libraries/LibGfx/PBMLoader.cpp
index 3dc89b991e..573c174fc4 100644
--- a/Userland/Libraries/LibGfx/PBMLoader.cpp
+++ b/Userland/Libraries/LibGfx/PBMLoader.cpp
@@ -195,11 +195,9 @@ size_t PBMImageDecoderPlugin::frame_count()
ImageFrameDescriptor PBMImageDecoderPlugin::frame(size_t i)
{
- if (i > 0) {
- return { bitmap(), 0 };
- }
-
- return {};
+ if (i > 0)
+ return {};
+ return { bitmap(), 0 };
}
}
diff --git a/Userland/Libraries/LibGfx/PGMLoader.cpp b/Userland/Libraries/LibGfx/PGMLoader.cpp
index e3fe486029..45a8f54121 100644
--- a/Userland/Libraries/LibGfx/PGMLoader.cpp
+++ b/Userland/Libraries/LibGfx/PGMLoader.cpp
@@ -198,11 +198,9 @@ size_t PGMImageDecoderPlugin::frame_count()
ImageFrameDescriptor PGMImageDecoderPlugin::frame(size_t i)
{
- if (i > 0) {
- return { bitmap(), 0 };
- }
-
- return {};
+ if (i > 0)
+ return {};
+ return { bitmap(), 0 };
}
}
diff --git a/Userland/Libraries/LibGfx/PNGLoader.cpp b/Userland/Libraries/LibGfx/PNGLoader.cpp
index 4129cec13c..af507efa35 100644
--- a/Userland/Libraries/LibGfx/PNGLoader.cpp
+++ b/Userland/Libraries/LibGfx/PNGLoader.cpp
@@ -1013,10 +1013,9 @@ size_t PNGImageDecoderPlugin::frame_count()
ImageFrameDescriptor PNGImageDecoderPlugin::frame(size_t i)
{
- if (i > 0) {
- return { bitmap(), 0 };
- }
- return {};
+ if (i > 0)
+ return {};
+ return { bitmap(), 0 };
}
}
diff --git a/Userland/Libraries/LibGfx/PPMLoader.cpp b/Userland/Libraries/LibGfx/PPMLoader.cpp
index 91cc921f8b..9517290ab6 100644
--- a/Userland/Libraries/LibGfx/PPMLoader.cpp
+++ b/Userland/Libraries/LibGfx/PPMLoader.cpp
@@ -200,11 +200,9 @@ size_t PPMImageDecoderPlugin::frame_count()
ImageFrameDescriptor PPMImageDecoderPlugin::frame(size_t i)
{
- if (i > 0) {
- return { bitmap(), 0 };
- }
-
- return {};
+ if (i > 0)
+ return {};
+ return { bitmap(), 0 };
}
}
diff --git a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp
index 1fc5755223..2a65d0f463 100644
--- a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp
+++ b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp
@@ -71,7 +71,8 @@ static bool build_image_document(DOM::Document& document, const ByteBuffer& data
auto image_decoder = Gfx::ImageDecoder::try_create(data.bytes());
if (!image_decoder)
return false;
- auto bitmap = image_decoder->bitmap();
+ auto frame = image_decoder->frame(0);
+ auto bitmap = frame.image;
if (!bitmap)
return false;
@@ -171,7 +172,8 @@ bool FrameLoader::load(const LoadRequest& request, Type type)
dbgln("No image decoder plugin for favicon {}", favicon_url);
return;
}
- auto bitmap = decoder->bitmap();
+ auto frame = decoder->frame(0);
+ auto bitmap = frame.image;
if (!bitmap) {
dbgln("Could not decode favicon {}", favicon_url);
return;
diff --git a/Userland/Services/ImageDecoder/ClientConnection.cpp b/Userland/Services/ImageDecoder/ClientConnection.cpp
index d47c4d46e9..3469a4ac83 100644
--- a/Userland/Services/ImageDecoder/ClientConnection.cpp
+++ b/Userland/Services/ImageDecoder/ClientConnection.cpp
@@ -52,14 +52,7 @@ Messages::ImageDecoderServer::DecodeImageResponse ClientConnection::decode_image
Vector<Gfx::ShareableBitmap> bitmaps;
Vector<u32> durations;
for (size_t i = 0; i < decoder->frame_count(); ++i) {
- // FIXME: All image decoder plugins should be rewritten to return frame() instead of bitmap().
- // Non-animated images can simply return 1 frame.
- Gfx::ImageFrameDescriptor frame;
- if (decoder->is_animated()) {
- frame = decoder->frame(i);
- } else {
- frame.image = decoder->bitmap();
- }
+ auto frame = decoder->frame(i);
if (frame.image)
bitmaps.append(frame.image->to_shareable_bitmap());
else