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.
This commit is contained in:
Andreas Kling 2021-07-27 01:29:50 +02:00
parent d01b4327fa
commit 751cb094ff
Notes: sideshowbarker 2024-07-18 08:03:51 +09:00
13 changed files with 35 additions and 49 deletions

View file

@ -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);

View file

@ -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 };
}
}

View file

@ -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 };
}
}

View file

@ -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 };
}
}

View file

@ -78,9 +78,4 @@ ImageDecoder::~ImageDecoder()
{
}
RefPtr<Gfx::Bitmap> ImageDecoder::bitmap() const
{
return m_plugin->bitmap();
}
}

View file

@ -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(); }

View file

@ -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 };
}
}

View file

@ -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 };
}
}

View file

@ -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 };
}
}

View file

@ -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 };
}
}

View file

@ -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 };
}
}

View file

@ -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;

View file

@ -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