]> git.tdb.fi Git - libs/gui.git/blobdiff - source/graphics/imageloader.cpp
Adjust Vulkan debug message output
[libs/gui.git] / source / graphics / imageloader.cpp
index 2c6ce217381f4dcbf1f33bec50104eeee6c1987c..859a34c12894a1a0460b439e230a0fe9154d1385 100644 (file)
@@ -1,6 +1,7 @@
 #include <msp/core/refptr.h>
 #include <msp/io/file.h>
 #include <msp/strings/format.h>
+#include <msp/strings/utils.h>
 #include "bmploader.h"
 #include "imageloader.h"
 #ifdef WITH_LIBPNG
@@ -31,6 +32,15 @@ ImageLoader::~ImageLoader()
        delete source;
 }
 
+bool ImageLoader::detect_signature(const std::string &sig)
+{
+       Registry &registry = get_registry();
+       for(list<RegisterBase *>::const_iterator i=registry.loaders.begin(); i!=registry.loaders.end(); ++i)
+               if((*i)->detect(sig))
+                       return true;
+       return false;
+}
+
 ImageLoader *ImageLoader::open_file(const string &fn)
 {
        try
@@ -58,9 +68,8 @@ ImageLoader *ImageLoader::open_io(IO::Seekable &io)
        if(registry.loaders.empty())
                throw unsupported_image_format("no loaders");
 
-       vector<char> sig_buf(registry.loaders.back()->get_signature_size());
-       unsigned sig_len = io.read(&sig_buf[0], sig_buf.size());
-       string signature(sig_buf.begin(), sig_buf.end());
+       string signature(registry.loaders.back()->get_signature_size(), 0);
+       unsigned sig_len = io.read(&signature[0], signature.size());
 
        ImageLoader *loader = 0;
        for(list<RegisterBase *>::const_iterator i=registry.loaders.begin(); (!loader && i!=registry.loaders.end()); ++i)
@@ -73,11 +82,7 @@ ImageLoader *ImageLoader::open_io(IO::Seekable &io)
        {
                string sig_hex;
                for(unsigned i=0; i<sig_len; ++i)
-               {
-                       if(i)
-                               sig_hex += ' ';
-                       sig_hex += format("%02X", static_cast<unsigned char>(sig_buf[i]));
-               }
+                       append(sig_hex, " ", format("%02X", static_cast<unsigned char>(signature[i])));
                throw unsupported_image_format(sig_hex);
        }
 
@@ -89,10 +94,23 @@ void ImageLoader::load(Image::Data &data)
        if(state>=FINISHED)
                throw logic_error("already loaded");
 
-       load_(data);
+       if(state<HEADERS_LOADED)
+               load_headers_(data);
+       if(!data.pixels)
+               data.pixels = data.owned_pixels = new char[data.stride*data.height];
+       load_pixels_(data);
        state = FINISHED;
 }
 
+void ImageLoader::load_headers(Image::Data &data)
+{
+       if(state>=HEADERS_LOADED)
+               throw logic_error("headers already loaded");
+
+       load_headers_(data);
+       state = HEADERS_LOADED;
+}
+
 ImageLoader::Registry &ImageLoader::get_registry()
 {
        static Registry registry;