#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);
+}
+
}
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);