#include <algorithm>
+#include <msp/strings/format.h>
#include <IL/il.h>
#include "devilloader.h"
return reinterpret_cast<Msp::IO::Seekable *>(handle)->tell();
}
+std::string error_string(ILenum err)
+{
+ switch(err)
+ {
+ case IL_FORMAT_NOT_SUPPORTED: return "Format not supported";
+ case IL_INTERNAL_ERROR: return "DevIL internal error";
+ case IL_INVALID_FILE_HEADER: return "Invalid file header";
+ case IL_FILE_READ_ERROR: return "File read error";
+ case IL_LIB_PNG_ERROR: return "LibPNG error";
+ case IL_LIB_JPEG_ERROR: return "LibJPEG error";
+ default: return Msp::format("Unknown error (%04X)", err);
+ }
+}
+
} // namespace
{
ilSetRead(0, 0, eof, get, read, seek, tell);
ilBindImage(id);
- ilLoadF(IL_TYPE_UNKNOWN, &io);
+
+ ilGetError();
+ if(!ilLoadF(IL_TYPE_UNKNOWN, &io))
+ throw bad_image_data(error_string(ilGetError()));
switch(ilGetInteger(IL_IMAGE_FORMAT))
{