X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgraphics%2Fimage.cpp;h=813672bca52d8fdec846629e53845af9c3a6dd17;hb=11ab96ba152e389814543a6398e2cd6f17a31092;hp=3e1124faaf06800158413189c054529db2ca4060;hpb=cfd3548464e6424fc9decf0539d6cd04b031ba10;p=libs%2Fgui.git diff --git a/source/graphics/image.cpp b/source/graphics/image.cpp index 3e1124f..813672b 100644 --- a/source/graphics/image.cpp +++ b/source/graphics/image.cpp @@ -1,8 +1,8 @@ +#include "image.h" #include #include #include #include -#include "image.h" #include "imageloader.h" using namespace std; @@ -10,16 +10,40 @@ using namespace std; namespace Msp { namespace Graphics { -Image::Data::Data(): - fmt(RGB), - width(0), - height(0), - data(0) -{ } +Image::Data::Data(const Data &other): + fmt(other.fmt), + width(other.width), + height(other.height), + stride(other.stride), + owned_pixels(other.pixels ? new char[stride*height] : nullptr), + pixels(owned_pixels) +{ + if(pixels) + copy(other.pixels, other.pixels+stride*height, pixels); +} + +Image::Data &Image::Data::operator=(const Data &other) +{ + delete[] owned_pixels; + pixels = owned_pixels = nullptr; + + fmt = other.fmt; + width = other.width; + height = other.height; + stride = other.stride; + + if(other.pixels) + { + pixels = owned_pixels = new char[stride*height]; + copy(other.pixels, other.pixels+stride*height, pixels); + } + + return *this; +} Image::Data::~Data() { - delete[] data; + delete[] owned_pixels; } @@ -29,7 +53,7 @@ void Image::load_file(const string &fn) load(*loader); } -void Image::load_io(IO::Base &io) +void Image::load_io(IO::Seekable &io) { RefPtr loader = ImageLoader::open_io(io); load(*loader); @@ -37,8 +61,23 @@ void Image::load_io(IO::Base &io) void Image::load(ImageLoader &loader) { + if(loader.get_state()==ImageLoader::INITIAL) + data = Data(); loader.load(data); } +void Image::load_into(ImageLoader &loader, void *buffer) +{ + data.pixels = reinterpret_cast(buffer); + load(loader); +} + +void Image::load_headers(ImageLoader &loader) +{ + if(loader.get_state()==ImageLoader::INITIAL) + data = Data(); + loader.load_headers(data); +} + } // namespace Graphics } // namespace Msp