-#ifdef WITH_DEVIL
-#include <IL/il.h>
-#endif
+#include <msp/core/refptr.h>
+#include <msp/fs/utils.h>
#include <msp/io/file.h>
#include <msp/io/memory.h>
#include "image.h"
-#include "image_devil.h"
-#include "image_png.h"
-#include "image_private.h"
+#include "imageloader.h"
using namespace std;
namespace Msp {
namespace Graphics {
-Image::Private::Private()
-{
-#ifdef WITH_DEVIL
- id = 0;
-#endif
- fmt = RGB;
- width = 0;
- height = 0;
- data = 0;
-}
+Image::Data::Data():
+ fmt(RGB),
+ width(0),
+ height(0),
+ data(0)
+{ }
-
-Image::Image():
- priv(new Private)
+Image::Data::~Data()
{
-#if !defined(WITH_DEVIL) && !defined(WITH_LIBPNG)
- throw runtime_error("no image support");
-#endif
+ delete[] data;
}
-Image::~Image()
-{
-#ifdef WITH_DEVIL
- if(priv->id)
- ilDeleteImages(1, &priv->id);
- else
-#endif
- delete[] priv->data;
- delete priv;
-}
void Image::load_file(const string &fn)
{
-#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
- load_devil_file(fn, *priv);
-#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
- load_devil_mem(data, size, *priv);
-#else
- throw unsupported_image_format("DevIL needed for non-PNG images");
-#endif
- }
- (void)data;
- (void)size;
-}
-
-PixelFormat Image::get_format() const
-{
- return priv->fmt;
-}
-
-unsigned Image::get_width() const
-{
- return priv->width;
+ RefPtr<ImageLoader> loader = ImageLoader::open_file(fn);
+ load(*loader);
}
-unsigned Image::get_height() const
+void Image::load_io(IO::Seekable &io)
{
- return priv->height;
+ RefPtr<ImageLoader> loader = ImageLoader::open_io(io);
+ load(*loader);
}
-const void *Image::get_data() const
+void Image::load(ImageLoader &loader)
{
- return priv->data;
+ loader.load(data);
}
} // namespace Graphics