mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:27:35 +00:00
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:
parent
d01b4327fa
commit
751cb094ff
13 changed files with 35 additions and 49 deletions
|
@ -81,7 +81,8 @@ void ImageWidget::load_from_file(const StringView& path)
|
||||||
m_image_decoder = Gfx::ImageDecoder::try_create(mapped_file.bytes());
|
m_image_decoder = Gfx::ImageDecoder::try_create(mapped_file.bytes());
|
||||||
VERIFY(m_image_decoder);
|
VERIFY(m_image_decoder);
|
||||||
|
|
||||||
auto bitmap = m_image_decoder->bitmap();
|
auto frame = m_image_decoder->frame(0);
|
||||||
|
auto bitmap = frame.image;
|
||||||
VERIFY(bitmap);
|
VERIFY(bitmap);
|
||||||
|
|
||||||
set_bitmap(bitmap);
|
set_bitmap(bitmap);
|
||||||
|
|
|
@ -1397,7 +1397,8 @@ size_t BMPImageDecoderPlugin::frame_count()
|
||||||
ImageFrameDescriptor BMPImageDecoderPlugin::frame(size_t i)
|
ImageFrameDescriptor BMPImageDecoderPlugin::frame(size_t i)
|
||||||
{
|
{
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
return { bitmap(), 0 };
|
return {};
|
||||||
return {};
|
return { bitmap(), 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1046,9 +1046,11 @@ size_t DDSImageDecoderPlugin::frame_count()
|
||||||
return 1;
|
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 };
|
return { bitmap(), 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -382,10 +382,9 @@ size_t ICOImageDecoderPlugin::frame_count()
|
||||||
|
|
||||||
ImageFrameDescriptor ICOImageDecoderPlugin::frame(size_t i)
|
ImageFrameDescriptor ICOImageDecoderPlugin::frame(size_t i)
|
||||||
{
|
{
|
||||||
if (i > 0) {
|
if (i > 0)
|
||||||
return { bitmap(), 0 };
|
return {};
|
||||||
}
|
return { bitmap(), 0 };
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,9 +78,4 @@ ImageDecoder::~ImageDecoder()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<Gfx::Bitmap> ImageDecoder::bitmap() const
|
|
||||||
{
|
|
||||||
return m_plugin->bitmap();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@ public:
|
||||||
virtual ~ImageDecoderPlugin() { }
|
virtual ~ImageDecoderPlugin() { }
|
||||||
|
|
||||||
virtual IntSize size() = 0;
|
virtual IntSize size() = 0;
|
||||||
virtual RefPtr<Gfx::Bitmap> bitmap() = 0;
|
|
||||||
|
|
||||||
virtual void set_volatile() = 0;
|
virtual void set_volatile() = 0;
|
||||||
[[nodiscard]] virtual bool set_nonvolatile(bool& was_purged) = 0;
|
[[nodiscard]] virtual bool set_nonvolatile(bool& was_purged) = 0;
|
||||||
|
@ -43,6 +42,8 @@ public:
|
||||||
virtual ImageFrameDescriptor frame(size_t i) = 0;
|
virtual ImageFrameDescriptor frame(size_t i) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual RefPtr<Gfx::Bitmap> bitmap() = 0;
|
||||||
|
|
||||||
ImageDecoderPlugin() { }
|
ImageDecoderPlugin() { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -54,7 +55,6 @@ public:
|
||||||
IntSize size() const { return m_plugin->size(); }
|
IntSize size() const { return m_plugin->size(); }
|
||||||
int width() const { return size().width(); }
|
int width() const { return size().width(); }
|
||||||
int height() const { return size().height(); }
|
int height() const { return size().height(); }
|
||||||
RefPtr<Gfx::Bitmap> bitmap() const;
|
|
||||||
void set_volatile() { m_plugin->set_volatile(); }
|
void set_volatile() { m_plugin->set_volatile(); }
|
||||||
[[nodiscard]] bool set_nonvolatile(bool& was_purged) { return m_plugin->set_nonvolatile(was_purged); }
|
[[nodiscard]] bool set_nonvolatile(bool& was_purged) { return m_plugin->set_nonvolatile(was_purged); }
|
||||||
bool sniff() const { return m_plugin->sniff(); }
|
bool sniff() const { return m_plugin->sniff(); }
|
||||||
|
|
|
@ -1327,9 +1327,9 @@ size_t JPGImageDecoderPlugin::frame_count()
|
||||||
|
|
||||||
ImageFrameDescriptor JPGImageDecoderPlugin::frame(size_t i)
|
ImageFrameDescriptor JPGImageDecoderPlugin::frame(size_t i)
|
||||||
{
|
{
|
||||||
if (i > 0) {
|
if (i > 0)
|
||||||
return { bitmap(), 0 };
|
return {};
|
||||||
}
|
return { bitmap(), 0 };
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,11 +195,9 @@ size_t PBMImageDecoderPlugin::frame_count()
|
||||||
|
|
||||||
ImageFrameDescriptor PBMImageDecoderPlugin::frame(size_t i)
|
ImageFrameDescriptor PBMImageDecoderPlugin::frame(size_t i)
|
||||||
{
|
{
|
||||||
if (i > 0) {
|
if (i > 0)
|
||||||
return { bitmap(), 0 };
|
return {};
|
||||||
}
|
return { bitmap(), 0 };
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,11 +198,9 @@ size_t PGMImageDecoderPlugin::frame_count()
|
||||||
|
|
||||||
ImageFrameDescriptor PGMImageDecoderPlugin::frame(size_t i)
|
ImageFrameDescriptor PGMImageDecoderPlugin::frame(size_t i)
|
||||||
{
|
{
|
||||||
if (i > 0) {
|
if (i > 0)
|
||||||
return { bitmap(), 0 };
|
return {};
|
||||||
}
|
return { bitmap(), 0 };
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1013,10 +1013,9 @@ size_t PNGImageDecoderPlugin::frame_count()
|
||||||
|
|
||||||
ImageFrameDescriptor PNGImageDecoderPlugin::frame(size_t i)
|
ImageFrameDescriptor PNGImageDecoderPlugin::frame(size_t i)
|
||||||
{
|
{
|
||||||
if (i > 0) {
|
if (i > 0)
|
||||||
return { bitmap(), 0 };
|
return {};
|
||||||
}
|
return { bitmap(), 0 };
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -200,11 +200,9 @@ size_t PPMImageDecoderPlugin::frame_count()
|
||||||
|
|
||||||
ImageFrameDescriptor PPMImageDecoderPlugin::frame(size_t i)
|
ImageFrameDescriptor PPMImageDecoderPlugin::frame(size_t i)
|
||||||
{
|
{
|
||||||
if (i > 0) {
|
if (i > 0)
|
||||||
return { bitmap(), 0 };
|
return {};
|
||||||
}
|
return { bitmap(), 0 };
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,8 @@ static bool build_image_document(DOM::Document& document, const ByteBuffer& data
|
||||||
auto image_decoder = Gfx::ImageDecoder::try_create(data.bytes());
|
auto image_decoder = Gfx::ImageDecoder::try_create(data.bytes());
|
||||||
if (!image_decoder)
|
if (!image_decoder)
|
||||||
return false;
|
return false;
|
||||||
auto bitmap = image_decoder->bitmap();
|
auto frame = image_decoder->frame(0);
|
||||||
|
auto bitmap = frame.image;
|
||||||
if (!bitmap)
|
if (!bitmap)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -171,7 +172,8 @@ bool FrameLoader::load(const LoadRequest& request, Type type)
|
||||||
dbgln("No image decoder plugin for favicon {}", favicon_url);
|
dbgln("No image decoder plugin for favicon {}", favicon_url);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto bitmap = decoder->bitmap();
|
auto frame = decoder->frame(0);
|
||||||
|
auto bitmap = frame.image;
|
||||||
if (!bitmap) {
|
if (!bitmap) {
|
||||||
dbgln("Could not decode favicon {}", favicon_url);
|
dbgln("Could not decode favicon {}", favicon_url);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -52,14 +52,7 @@ Messages::ImageDecoderServer::DecodeImageResponse ClientConnection::decode_image
|
||||||
Vector<Gfx::ShareableBitmap> bitmaps;
|
Vector<Gfx::ShareableBitmap> bitmaps;
|
||||||
Vector<u32> durations;
|
Vector<u32> durations;
|
||||||
for (size_t i = 0; i < decoder->frame_count(); ++i) {
|
for (size_t i = 0; i < decoder->frame_count(); ++i) {
|
||||||
// FIXME: All image decoder plugins should be rewritten to return frame() instead of bitmap().
|
auto frame = decoder->frame(i);
|
||||||
// Non-animated images can simply return 1 frame.
|
|
||||||
Gfx::ImageFrameDescriptor frame;
|
|
||||||
if (decoder->is_animated()) {
|
|
||||||
frame = decoder->frame(i);
|
|
||||||
} else {
|
|
||||||
frame.image = decoder->bitmap();
|
|
||||||
}
|
|
||||||
if (frame.image)
|
if (frame.image)
|
||||||
bitmaps.append(frame.image->to_shareable_bitmap());
|
bitmaps.append(frame.image->to_shareable_bitmap());
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue