3 #include "image_devil.h"
4 #include "image_private.h"
10 using namespace Msp::Graphics;
12 void init_load(Image::Private &priv)
14 static bool il_init_done = false;
19 ilEnable(IL_ORIGIN_SET);
20 ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
25 ilGenImages(1, &priv.id);
29 void finish_load(Image::Private &priv)
31 switch(ilGetInteger(IL_IMAGE_FORMAT))
33 case IL_COLOR_INDEX: priv.fmt = COLOR_INDEX; break;
34 case IL_LUMINANCE: priv.fmt = LUMINANCE; break;
35 case IL_LUMINANCE_ALPHA: priv.fmt = LUMINANCE_ALPHA; break;
36 case IL_RGB: priv.fmt = RGB; break;
37 case IL_RGBA: priv.fmt = RGBA; break;
38 case IL_BGR: priv.fmt = BGR; break;
39 case IL_BGRA: priv.fmt = BGRA; break;
40 default: throw unsupported_image_format("unknown pixel format");
43 priv.width = ilGetInteger(IL_IMAGE_WIDTH);
44 priv.height = ilGetInteger(IL_IMAGE_HEIGHT);
45 priv.data = reinterpret_cast<char *>(ilGetData());
56 void load_devil_file(const string &fn, Image::Private &priv)
59 if(!ilLoadImage(const_cast<char *>(fn.c_str())))
60 throw bad_image_data("IL error");
64 void load_devil_mem(const void *data, unsigned size, Image::Private &priv)
67 if(!ilLoadL(IL_TYPE_UNKNOWN, const_cast<void *>(data), size))
68 throw bad_image_data("IL error");
72 } // namespace Graphics