ImageLoader.h 862 B

1234567891011121314151617181920212223242526272829303132333435
  1. #pragma once
  2. #include <AK/NonnullRefPtr.h>
  3. #include <AK/OwnPtr.h>
  4. #include <AK/RefCounted.h>
  5. #include <LibDraw/Size.h>
  6. class GraphicsBitmap;
  7. class ImageLoaderPlugin {
  8. public:
  9. virtual ~ImageLoaderPlugin() {}
  10. virtual Size size() = 0;
  11. virtual RefPtr<GraphicsBitmap> bitmap() = 0;
  12. protected:
  13. ImageLoaderPlugin() {}
  14. };
  15. class ImageLoader : public RefCounted<ImageLoader> {
  16. public:
  17. static NonnullRefPtr<ImageLoader> create(const u8* data, size_t size) { return adopt(*new ImageLoader(data, size)); }
  18. ~ImageLoader();
  19. Size size() const { return m_plugin->size(); }
  20. int width() const { return size().width(); }
  21. int height() const { return size().height(); }
  22. RefPtr<GraphicsBitmap> bitmap() const { return m_plugin->bitmap(); }
  23. private:
  24. ImageLoader(const u8*, size_t);
  25. mutable OwnPtr<ImageLoaderPlugin> m_plugin;
  26. };