X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgraphics%2Fimageloader.h;h=d824291eb65086aefdad641e2d9ef5dbca873a56;hb=b99a9eb342d0f6ba5509c6d9f8ab0b0b5d5d2979;hp=f953990c696458dffb587d0a3fd3889fe10b9975;hpb=8e403dbbcde6efee1862f6d501ce30a3e7ba81c4;p=libs%2Fgui.git diff --git a/source/graphics/imageloader.h b/source/graphics/imageloader.h index f953990..d824291 100644 --- a/source/graphics/imageloader.h +++ b/source/graphics/imageloader.h @@ -2,41 +2,100 @@ #define MSP_GRAPHICS_IMAGELOADER_H_ #include "image.h" +#include "mspgui_api.h" namespace Msp { namespace Graphics { -class unsupported_image_format: public std::runtime_error +class MSPGUI_API unsupported_image_format: public std::runtime_error { public: unsupported_image_format(const std::string &w): std::runtime_error(w) { } - virtual ~unsupported_image_format() throw() { } }; -class bad_image_data: public std::runtime_error +class MSPGUI_API bad_image_data: public std::runtime_error { public: bad_image_data(const std::string &w): std::runtime_error(w) { } - virtual ~bad_image_data() throw() { } }; -class ImageLoader +class MSPGUI_API ImageLoader { -private: - IO::Base *source; +public: + enum State + { + INITIAL, + HEADERS_LOADED, + FINISHED + }; + protected: + class RegisterBase + { + protected: + RegisterBase() = default; + public: + virtual ~RegisterBase() = default; + + virtual unsigned get_signature_size() const = 0; + virtual bool detect(const std::string &) const = 0; + virtual ImageLoader *create(IO::Seekable &) const = 0; + }; + + template + class RegisteredLoader: public RegisterBase + { + public: + unsigned get_signature_size() const override { return T::get_signature_size(); } + bool detect(const std::string &s) const override { return T::detect(s); } + ImageLoader *create(IO::Seekable &io) const override { return new T(io); } + }; + + struct Registry + { + std::vector loaders; + bool changed = false; + + ~Registry(); + }; + +private: + IO::Base *source = nullptr; + State state = INITIAL; - ImageLoader(); +protected: + ImageLoader() = default; public: virtual ~ImageLoader(); + static bool detect_signature(const std::string &); static ImageLoader *open_file(const std::string &); static ImageLoader *open_io(IO::Seekable &); - virtual void load(Image::Data &) = 0; + virtual void load(Image::Data &); + virtual void load_headers(Image::Data &); +protected: + virtual void load_headers_(Image::Data &) = 0; + virtual void load_pixels_(Image::Data &) = 0; + +public: + State get_state() const { return state; } + + template + static void register_loader(); +private: + static Registry &get_registry(); }; +template +void ImageLoader::register_loader() +{ + Registry ®istry = get_registry(); + registry.loaders.push_back(new RegisteredLoader); + registry.changed = true; +} + } // namespace Graphics } // namespace Msp