1 #ifndef MSP_GRAPHICS_IMAGELOADER_H_
2 #define MSP_GRAPHICS_IMAGELOADER_H_
5 #include "mspgui_api.h"
10 class MSPGUI_API unsupported_image_format: public std::runtime_error
13 unsupported_image_format(const std::string &w): std::runtime_error(w) { }
16 class MSPGUI_API bad_image_data: public std::runtime_error
19 bad_image_data(const std::string &w): std::runtime_error(w) { }
23 class MSPGUI_API ImageLoader
39 virtual ~RegisterBase() { }
41 virtual unsigned get_signature_size() const = 0;
42 virtual bool detect(const std::string &) const = 0;
43 virtual ImageLoader *create(IO::Seekable &) const = 0;
47 class RegisteredLoader: public RegisterBase
50 unsigned get_signature_size() const override { return T::get_signature_size(); }
51 bool detect(const std::string &s) const override { return T::detect(s); }
52 ImageLoader *create(IO::Seekable &io) const override { return new T(io); }
57 std::vector<RegisterBase *> loaders;
64 IO::Base *source = nullptr;
65 State state = INITIAL;
68 ImageLoader() = default;
70 virtual ~ImageLoader();
72 static bool detect_signature(const std::string &);
73 static ImageLoader *open_file(const std::string &);
74 static ImageLoader *open_io(IO::Seekable &);
76 virtual void load(Image::Data &);
77 virtual void load_headers(Image::Data &);
79 virtual void load_headers_(Image::Data &) = 0;
80 virtual void load_pixels_(Image::Data &) = 0;
83 State get_state() const { return state; }
86 static void register_loader();
88 static Registry &get_registry();
92 void ImageLoader::register_loader()
94 Registry ®istry = get_registry();
95 registry.loaders.push_back(new RegisteredLoader<T>);
96 registry.changed = true;
99 } // namespace Graphics