-#ifdef WITH_LIBPNG
- if(fn.size()>4 && !fn.compare(fn.size()-4, 4, ".png"))
- {
- IO::BufferedFile file(fn);
- load_png(file, *priv);
- }
- else
-#endif
- {
-#ifdef WITH_DEVIL
- ensure_devil_image(priv->id);
- ilBindImage(priv->id);
- if(!ilLoadImage(const_cast<char *>(fn.c_str())))
- throw bad_image_data("IL error");
-#else
- throw unsupported_image_format("DevIL needed for non-PNG images");
-#endif
- }
- (void)fn;
-}
-
-void Image::load_memory(const void *data, unsigned size)
-{
-#ifdef WITH_LIBPNG
- if(size>=8 && is_png(data, 8))
- {
- IO::Memory mem(reinterpret_cast<const char *>(data), size);
- load_png(mem, *priv);
- }
- else
-#endif
- {
-#ifdef WITH_DEVIL
- ensure_devil_image(priv->id);
- ilBindImage(priv->id);
- if(!ilLoadL(IL_TYPE_UNKNOWN, const_cast<void *>(data), size))
- throw bad_image_data("IL error");
-#else
- throw unsupported_image_format("DevIL needed for non-PNG images");
-#endif
- }
- (void)data;
- (void)size;
-}
-
-PixelFormat Image::get_format() const
-{
-#ifdef WITH_LIBPNG
- if(priv->data)
- return priv->fmt;
-#endif
-#ifdef WITH_DEVIL
- if(priv->id)
- {
- ilBindImage(priv->id);
- 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;
- // XXX bad, should throw when loading
- default: throw invalid_argument("unknown pixel format in image");
- }
- }
-#endif
- return RGB;
-}
-
-unsigned Image::get_width() const
-{
-#ifdef WITH_LIBPNG
- if(priv->data)
- return priv->width;
-#endif
-#ifdef WITH_DEVIL
- if(priv->id)
- {
- ilBindImage(priv->id);
- return ilGetInteger(IL_IMAGE_WIDTH);
- }
-#endif
- return 0;