--- /dev/null
+/* $Id$
+
+This file is part of libmspgl
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#include <IL/il.h>
+#include <msp/core/except.h>
+#include "ilwrap.h"
+
+namespace Msp {
+namespace GL {
+
+Image::Image()
+{
+ if(!init_done)
+ {
+ ilInit();
+ ilEnable(IL_ORIGIN_SET);
+ ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
+ init_done=true;
+ }
+
+ ilGenImages(1, &id);
+}
+
+Image::~Image()
+{
+ ilDeleteImages(1, &id);
+}
+
+void Image::load(const std::string &fn)
+{
+ ilBindImage(id);
+ if(!ilLoadImage(const_cast<char *>(fn.c_str())))
+ throw Exception("Error loading image "+fn);
+}
+
+PixelFormat Image::get_format() const
+{
+ switch(ilGetInteger(IL_IMAGE_FORMAT))
+ {
+ case IL_COLOR_INDEX: return COLOR_INDEX;
+ case IL_LUMINANCE: return LUMINANCE;
+ case IL_LUMINANCE_ALPHA: return LUMINANCE_ALPHA;
+ case IL_RGB: return RGB;
+ case IL_RGBA: return RGBA;
+ case IL_BGR: return BGR;
+ case IL_BGRA: return BGRA;
+ default: throw InvalidParameterValue("Unknown pixel format in image");
+ }
+}
+
+unsigned Image::get_width() const
+{
+ return ilGetInteger(IL_IMAGE_WIDTH);
+}
+
+unsigned Image::get_height() const
+{
+ return ilGetInteger(IL_IMAGE_HEIGHT);
+}
+
+const void *Image::get_data() const
+{
+ return ilGetData();
+}
+
+bool Image::init_done=false;
+
+} // namespace GL
+} // namespace Msp