mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:27:35 +00:00
LibDraw: Add ImageLoader, a simple abstraction for image loading
An ImageLoader is a generic interface for loading encoded image data of any supported format. It has an ImageLoaderPlugin internally that does all the work. This patch adds an initial PNGImageLoaderPlugin that knows how to retrieve the size of a PNG, and the bitmap. The API is divided into size() and bitmap() to facilitate geometry-only decoding. This will be useful in places like LibHTML where we need dimensions for layout purposes but can wait with the bitmap until later.
This commit is contained in:
parent
5c2b21705a
commit
1bd2941467
5 changed files with 138 additions and 12 deletions
35
Libraries/LibDraw/ImageLoader.h
Normal file
35
Libraries/LibDraw/ImageLoader.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <AK/RefCounted.h>
|
||||
#include <LibDraw/Size.h>
|
||||
|
||||
class GraphicsBitmap;
|
||||
|
||||
class ImageLoaderPlugin {
|
||||
public:
|
||||
virtual ~ImageLoaderPlugin() {}
|
||||
|
||||
virtual Size size() = 0;
|
||||
virtual RefPtr<GraphicsBitmap> bitmap() = 0;
|
||||
|
||||
protected:
|
||||
ImageLoaderPlugin() {}
|
||||
};
|
||||
|
||||
class ImageLoader : public RefCounted<ImageLoader> {
|
||||
public:
|
||||
static NonnullRefPtr<ImageLoader> create(const u8* data, size_t size) { return adopt(*new ImageLoader(data, size)); }
|
||||
~ImageLoader();
|
||||
|
||||
Size size() const { return m_plugin->size(); }
|
||||
int width() const { return size().width(); }
|
||||
int height() const { return size().height(); }
|
||||
RefPtr<GraphicsBitmap> bitmap() const { return m_plugin->bitmap(); }
|
||||
|
||||
private:
|
||||
ImageLoader(const u8*, size_t);
|
||||
|
||||
mutable OwnPtr<ImageLoaderPlugin> m_plugin;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue