3 This file is part of libmspgbase
4 Copyright © 2007-2008 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
11 #include <msp/core/except.h>
22 static bool init_done=false;
27 ilEnable(IL_ORIGIN_SET);
28 ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
34 throw Exception("DevIL support not compiled in");
41 ilDeleteImages(1, &id);
45 void Image::load_file(const string &fn)
49 if(!ilLoadImage(const_cast<char *>(fn.c_str())))
50 throw Exception("Error loading image "+fn);
56 void Image::load_memory(const void *data, unsigned size)
60 if(!ilLoadL(IL_TYPE_UNKNOWN, const_cast<void *>(data), size))
61 throw Exception("Error loading image from lump");
63 (void)data; (void)size;
67 PixelFormat Image::get_format() const
70 switch(ilGetInteger(IL_IMAGE_FORMAT))
72 case IL_COLOR_INDEX: return COLOR_INDEX;
73 case IL_LUMINANCE: return LUMINANCE;
74 case IL_LUMINANCE_ALPHA: return LUMINANCE_ALPHA;
75 case IL_RGB: return RGB;
76 case IL_RGBA: return RGBA;
77 case IL_BGR: return BGR;
78 case IL_BGRA: return BGRA;
79 default: throw InvalidParameterValue("Unknown pixel format in image");
86 unsigned Image::get_width() const
89 return ilGetInteger(IL_IMAGE_WIDTH);
95 unsigned Image::get_height() const
98 return ilGetInteger(IL_IMAGE_HEIGHT);
104 const void *Image::get_data() const
113 } // namespace Graphics