X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgraphics%2Fimage.cpp;h=a0e6e380ad24d54b20c5144c6001208147f9dbc5;hb=8e58f5bca4258e73e84e604ff2573fe9713b7b3f;hp=46c2b3fab3c29f0ce952133b1d55966531252e94;hpb=1ca709deba08e55d95066be564a8fd43a321af19;p=libs%2Fgui.git diff --git a/source/graphics/image.cpp b/source/graphics/image.cpp index 46c2b3f..a0e6e38 100644 --- a/source/graphics/image.cpp +++ b/source/graphics/image.cpp @@ -1,107 +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) -{ - string ext = FS::extpart(fn); -#ifdef WITH_LIBPNG - if(ext==".png") - { - IO::BufferedFile file(fn); - load_png(file, *priv, 0, 0); - } - 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_io(IO::Base &io) -{ - char sig_buf[8]; - unsigned sig_len = io.read(sig_buf, sizeof(sig_buf)); -#ifdef WITH_LIBPNG - if(sig_len==sizeof(sig_buf) && is_png(sig_buf, sig_len)) - load_png(io, *priv, sig_buf, sig_len); - else -#endif + if(other.data) { -#ifdef WITH_DEVIL - load_devil_io(io, *priv, sig_buf, sig_len); -#else - throw unsupported_image_format("DevIL needed for non-PNG images"); -#endif + data = new char[stride*height]; + copy(other.data, other.data+stride*height, data); } + + 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