3 This file is part of libmspgl
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
9 #include <msp/core/except.h>
19 static bool init_done=false;
24 ilEnable(IL_ORIGIN_SET);
25 ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
34 ilDeleteImages(1, &id);
37 void Image::load_file(const string &fn)
40 if(!ilLoadImage(const_cast<char *>(fn.c_str())))
41 throw Exception("Error loading image "+fn);
44 void Image::load_lump(const void *data, unsigned size)
47 if(!ilLoadL(IL_TYPE_UNKNOWN, const_cast<void *>(data), size))
48 throw Exception("Error loading image from lump");
51 PixelFormat Image::get_format() const
53 switch(ilGetInteger(IL_IMAGE_FORMAT))
55 case IL_COLOR_INDEX: return COLOR_INDEX;
56 case IL_LUMINANCE: return LUMINANCE;
57 case IL_LUMINANCE_ALPHA: return LUMINANCE_ALPHA;
58 case IL_RGB: return RGB;
59 case IL_RGBA: return RGBA;
60 case IL_BGR: return BGR;
61 case IL_BGRA: return BGRA;
62 default: throw InvalidParameterValue("Unknown pixel format in image");
66 unsigned Image::get_width() const
68 return ilGetInteger(IL_IMAGE_WIDTH);
71 unsigned Image::get_height() const
73 return ilGetInteger(IL_IMAGE_HEIGHT);
76 const void *Image::get_data() const