1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 19:35:08 +00:00

LibDraw: Rename ImageLoader => ImageDecoder

ImageLoader was not the right name for this, as there is no loading
happening, only decoding. :^)
This commit is contained in:
Andreas Kling 2019-10-19 19:56:49 +02:00
parent 02e787f8a4
commit f970578cd4
8 changed files with 32 additions and 32 deletions

View file

@ -0,0 +1,11 @@
#include <LibDraw/ImageDecoder.h>
#include <LibDraw/PNGLoader.h>
ImageDecoder::ImageDecoder(const u8* data, size_t size)
{
m_plugin = make<PNGImageDecoderPlugin>(data, size);
}
ImageDecoder::~ImageDecoder()
{
}

View file

@ -7,21 +7,21 @@
class GraphicsBitmap; class GraphicsBitmap;
class ImageLoaderPlugin { class ImageDecoderPlugin {
public: public:
virtual ~ImageLoaderPlugin() {} virtual ~ImageDecoderPlugin() {}
virtual Size size() = 0; virtual Size size() = 0;
virtual RefPtr<GraphicsBitmap> bitmap() = 0; virtual RefPtr<GraphicsBitmap> bitmap() = 0;
protected: protected:
ImageLoaderPlugin() {} ImageDecoderPlugin() {}
}; };
class ImageLoader : public RefCounted<ImageLoader> { class ImageDecoder : public RefCounted<ImageDecoder> {
public: public:
static NonnullRefPtr<ImageLoader> create(const u8* data, size_t size) { return adopt(*new ImageLoader(data, size)); } static NonnullRefPtr<ImageDecoder> create(const u8* data, size_t size) { return adopt(*new ImageDecoder(data, size)); }
~ImageLoader(); ~ImageDecoder();
Size size() const { return m_plugin->size(); } Size size() const { return m_plugin->size(); }
int width() const { return size().width(); } int width() const { return size().width(); }
@ -29,7 +29,7 @@ public:
RefPtr<GraphicsBitmap> bitmap() const { return m_plugin->bitmap(); } RefPtr<GraphicsBitmap> bitmap() const { return m_plugin->bitmap(); }
private: private:
ImageLoader(const u8*, size_t); ImageDecoder(const u8*, size_t);
mutable OwnPtr<ImageLoaderPlugin> m_plugin; mutable OwnPtr<ImageDecoderPlugin> m_plugin;
}; };

View file

@ -1,11 +0,0 @@
#include <LibDraw/ImageLoader.h>
#include <LibDraw/PNGLoader.h>
ImageLoader::ImageLoader(const u8* data, size_t size)
{
m_plugin = make<PNGImageLoaderPlugin>(data, size);
}
ImageLoader::~ImageLoader()
{
}

View file

@ -8,7 +8,7 @@ OBJS = \
GraphicsBitmap.o \ GraphicsBitmap.o \
Painter.o \ Painter.o \
PNGLoader.o \ PNGLoader.o \
ImageLoader.o \ ImageDecoder.o \
Rect.o \ Rect.o \
StylePainter.o \ StylePainter.o \
Emoji.o Emoji.o

View file

@ -661,18 +661,18 @@ static bool process_chunk(Streamer& streamer, PNGLoadingContext& context, bool d
return true; return true;
} }
PNGImageLoaderPlugin::PNGImageLoaderPlugin(const u8* data, size_t size) PNGImageDecoderPlugin::PNGImageDecoderPlugin(const u8* data, size_t size)
{ {
m_context = make<PNGLoadingContext>(); m_context = make<PNGLoadingContext>();
m_context->data = data; m_context->data = data;
m_context->data_size = size; m_context->data_size = size;
} }
PNGImageLoaderPlugin::~PNGImageLoaderPlugin() PNGImageDecoderPlugin::~PNGImageDecoderPlugin()
{ {
} }
Size PNGImageLoaderPlugin::size() Size PNGImageDecoderPlugin::size()
{ {
if (m_context->state == PNGLoadingContext::State::Error) if (m_context->state == PNGLoadingContext::State::Error)
return {}; return {};
@ -686,7 +686,7 @@ Size PNGImageLoaderPlugin::size()
return { m_context->width, m_context->height }; return { m_context->width, m_context->height };
} }
RefPtr<GraphicsBitmap> PNGImageLoaderPlugin::bitmap() RefPtr<GraphicsBitmap> PNGImageDecoderPlugin::bitmap()
{ {
if (m_context->state == PNGLoadingContext::State::Error) if (m_context->state == PNGLoadingContext::State::Error)
return nullptr; return nullptr;

View file

@ -1,17 +1,17 @@
#pragma once #pragma once
#include <LibDraw/GraphicsBitmap.h> #include <LibDraw/GraphicsBitmap.h>
#include <LibDraw/ImageLoader.h> #include <LibDraw/ImageDecoder.h>
RefPtr<GraphicsBitmap> load_png(const StringView& path); RefPtr<GraphicsBitmap> load_png(const StringView& path);
RefPtr<GraphicsBitmap> load_png_from_memory(const u8*, size_t); RefPtr<GraphicsBitmap> load_png_from_memory(const u8*, size_t);
struct PNGLoadingContext; struct PNGLoadingContext;
class PNGImageLoaderPlugin final : public ImageLoaderPlugin { class PNGImageDecoderPlugin final : public ImageDecoderPlugin {
public: public:
virtual ~PNGImageLoaderPlugin() override; virtual ~PNGImageDecoderPlugin() override;
PNGImageLoaderPlugin(const u8*, size_t); PNGImageDecoderPlugin(const u8*, size_t);
virtual Size size() override; virtual Size size() override;
virtual RefPtr<GraphicsBitmap> bitmap() override; virtual RefPtr<GraphicsBitmap> bitmap() override;

View file

@ -34,7 +34,7 @@ void HTMLImageElement::load_image(const String& src)
} }
m_image_data = data; m_image_data = data;
m_image_loader = ImageLoader::create(m_image_data.data(), m_image_data.size()); m_image_loader = ImageDecoder::create(m_image_data.data(), m_image_data.size());
document().update_layout(); document().update_layout();
}); });
} }

View file

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <LibDraw/GraphicsBitmap.h> #include <LibDraw/GraphicsBitmap.h>
#include <LibDraw/ImageLoader.h> #include <LibDraw/ImageDecoder.h>
#include <LibHTML/DOM/HTMLElement.h> #include <LibHTML/DOM/HTMLElement.h>
class HTMLImageElement : public HTMLElement { class HTMLImageElement : public HTMLElement {
@ -17,14 +17,14 @@ public:
int preferred_height() const; int preferred_height() const;
const GraphicsBitmap* bitmap() const; const GraphicsBitmap* bitmap() const;
const ImageLoader* image_loader() const { return m_image_loader; } const ImageDecoder* image_loader() const { return m_image_loader; }
private: private:
void load_image(const String& src); void load_image(const String& src);
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override; virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
RefPtr<ImageLoader> m_image_loader; RefPtr<ImageDecoder> m_image_loader;
mutable RefPtr<GraphicsBitmap> m_bitmap; mutable RefPtr<GraphicsBitmap> m_bitmap;
ByteBuffer m_image_data; ByteBuffer m_image_data;
}; };