]> git.tdb.fi Git - libs/gui.git/commitdiff
Better PNG error reporting
authorMikko Rasa <tdb@tdb.fi>
Fri, 26 Aug 2011 11:52:37 +0000 (14:52 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 26 Aug 2011 11:52:37 +0000 (14:52 +0300)
source/graphics/image_png.cpp

index 256159c6880fc1de70ab563f6c702ab24301cca3..f2247863dac57d8f2636af3eaadeb5dc4a8f6edd 100644 (file)
@@ -3,14 +3,28 @@
 #include "image_png.h"
 #include "image_private.h"
 
+using namespace std;
+
 namespace {
 
+struct ErrorInfo
+{
+       string msg;
+};
+
 void read(png_struct *png, png_byte *data, png_size_t size)
 {
        Msp::IO::Base *in = reinterpret_cast<Msp::IO::Base *>(png_get_io_ptr(png));
        in->read(reinterpret_cast<char *>(data), size);
 }
 
+void error(png_struct *png, const char *msg)
+{
+       ErrorInfo *error_info = reinterpret_cast<ErrorInfo *>(png_get_error_ptr(png));
+       error_info->msg = msg;
+       longjmp(png_jmpbuf(png), 1);
+}
+
 }
 
 
@@ -30,11 +44,12 @@ void load_png(IO::Base &in, Image::Private &priv)
 
        try
        {
-               png = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
+               ErrorInfo error_info;
+               png = png_create_read_struct(PNG_LIBPNG_VER_STRING, &error_info, error, 0);
                info = png_create_info_struct(png);
 
                if(setjmp(png_jmpbuf(png)))
-                       throw bad_image_data("PNG error");
+                       throw bad_image_data(error_info.msg);
 
                png_set_read_fn(png, &in, read);
                png_read_info(png, info);