X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgraphics%2Fimage.cpp;h=2903d499f75cfcb815a02f48de869b875bff54ef;hb=2ed9d7a0a96638bdf0614c1cf858719e7ced40d3;hp=b22be1969d057e161cd60af0be3d9785c320b438;hpb=8e403dbbcde6efee1862f6d501ce30a3e7ba81c4;p=libs%2Fgui.git diff --git a/source/graphics/image.cpp b/source/graphics/image.cpp index b22be19..2903d49 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; @@ -14,12 +14,44 @@ Image::Data::Data(): fmt(RGB), width(0), height(0), - data(0) + owned_pixels(0), + pixels(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] : 0), + 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 = 0; + + 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; } @@ -37,8 +69,23 @@ void Image::load_io(IO::Seekable &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