X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgraphics%2Fimage.cpp;h=a0e6e380ad24d54b20c5144c6001208147f9dbc5;hb=8e58f5bca4258e73e84e604ff2573fe9713b7b3f;hp=6a20178c5d4a5d115ed1748100374d13a3e03f38;hpb=1b8d9d3ea7152ea2e25ff252bc100aee2a6d6218;p=libs%2Fgui.git diff --git a/source/graphics/image.cpp b/source/graphics/image.cpp index 6a20178..a0e6e38 100644 --- a/source/graphics/image.cpp +++ b/source/graphics/image.cpp @@ -1,108 +1,73 @@ -#ifdef WITH_DEVIL -#include -#endif +#include +#include #include #include #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(const Data &other): + fmt(other.fmt), + width(other.width), + height(other.height), + stride(other.stride), + data(other.data ? new char[stride*height] : 0) { -#if !defined(WITH_DEVIL) && !defined(WITH_LIBPNG) - throw runtime_error("no image support"); -#endif + if(data) + copy(other.data, other.data+stride*height, data); } -Image::~Image() +Image::Data &Image::Data::operator=(const Data &other) { -#ifdef WITH_DEVIL - if(priv->id) - ilDeleteImages(1, &priv->id); - else -#endif - delete[] priv->data; - delete priv; -} + delete[] data; + data = 0; -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; -} + fmt = other.fmt; + width = other.width; + height = other.height; + stride = other.stride; -void Image::load_memory(const void *data, unsigned size) -{ -#ifdef WITH_LIBPNG - if(size>=8 && is_png(data, 8)) + if(other.data) { - IO::Memory mem(reinterpret_cast(data), size); - load_png(mem, *priv); + data = new char[stride*height]; + copy(other.data, other.data+stride*height, data); } - 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; + + return *this; } -PixelFormat Image::get_format() const +Image::Data::~Data() { - return priv->fmt; + delete[] data; } -unsigned Image::get_width() const + +void Image::load_file(const string &fn) { - return priv->width; + RefPtr loader = ImageLoader::open_file(fn); + load(*loader); } -unsigned Image::get_height() const +void Image::load_io(IO::Seekable &io) { - return priv->height; + RefPtr 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