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;
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();
90 static bool signature_size_compare(RegisterBase *, RegisterBase *);
94 void ImageLoader::register_loader()
96 Registry ®istry = get_registry();
97 registry.loaders.push_back(new RegisteredLoader<T>);
98 registry.changed = true;
101 } // namespace Graphics