From: Mikko Rasa Date: Fri, 26 Aug 2011 11:52:37 +0000 (+0300) Subject: Better PNG error reporting X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=1f842b63c6e1751b2017f5c4b67d50e2fc911e55;p=libs%2Fgui.git Better PNG error reporting --- diff --git a/source/graphics/image_png.cpp b/source/graphics/image_png.cpp index 256159c..f224786 100644 --- a/source/graphics/image_png.cpp +++ b/source/graphics/image_png.cpp @@ -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(png_get_io_ptr(png)); in->read(reinterpret_cast(data), size); } +void error(png_struct *png, const char *msg) +{ + ErrorInfo *error_info = reinterpret_cast(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);