1 #ifndef MSP_GRAPHICS_IMAGELOADER_H_
2 #define MSP_GRAPHICS_IMAGELOADER_H_
9 class unsupported_image_format: public std::runtime_error
12 unsupported_image_format(const std::string &w): std::runtime_error(w) { }
15 class bad_image_data: public std::runtime_error
18 bad_image_data(const std::string &w): std::runtime_error(w) { }
38 virtual ~RegisterBase() { }
40 virtual unsigned get_signature_size() const = 0;
41 virtual bool detect(const std::string &) const = 0;
42 virtual ImageLoader *create(IO::Seekable &) const = 0;
46 class RegisteredLoader: public RegisterBase
49 unsigned get_signature_size() const override { return T::get_signature_size(); }
50 bool detect(const std::string &s) const override { return T::detect(s); }
51 ImageLoader *create(IO::Seekable &io) const override { return new T(io); }
56 std::list<RegisterBase *> loaders;
64 State state = INITIAL;
67 ImageLoader() = default;
69 virtual ~ImageLoader();
71 static bool detect_signature(const std::string &);
72 static ImageLoader *open_file(const std::string &);
73 static ImageLoader *open_io(IO::Seekable &);
75 virtual void load(Image::Data &);
76 virtual void load_headers(Image::Data &);
78 virtual void load_headers_(Image::Data &) = 0;
79 virtual void load_pixels_(Image::Data &) = 0;
82 State get_state() const { return state; }
85 static void register_loader();
87 static Registry &get_registry();
89 static bool signature_size_compare(RegisterBase *, RegisterBase *);
93 void ImageLoader::register_loader()
95 Registry ®istry = get_registry();
96 registry.loaders.push_back(new RegisteredLoader<T>);
97 registry.changed = true;
100 } // namespace Graphics