X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgraphics%2Fimage.cpp;h=2835d05e872936d0cc069fa806812ff3ab952661;hb=917c43de100807f4397e36b66b1a748dbf44370e;hp=a0e6e380ad24d54b20c5144c6001208147f9dbc5;hpb=8e58f5bca4258e73e84e604ff2573fe9713b7b3f;p=libs%2Fgui.git diff --git a/source/graphics/image.cpp b/source/graphics/image.cpp index a0e6e38..2835d05 100644 --- a/source/graphics/image.cpp +++ b/source/graphics/image.cpp @@ -14,7 +14,8 @@ Image::Data::Data(): fmt(RGB), width(0), height(0), - data(0) + owned_pixels(0), + pixels(0) { } Image::Data::Data(const Data &other): @@ -22,26 +23,27 @@ Image::Data::Data(const Data &other): width(other.width), height(other.height), stride(other.stride), - data(other.data ? new char[stride*height] : 0) + owned_pixels(other.pixels ? new char[stride*height] : 0), + pixels(owned_pixels) { - if(data) - copy(other.data, other.data+stride*height, data); + if(pixels) + copy(other.pixels, other.pixels+stride*height, pixels); } Image::Data &Image::Data::operator=(const Data &other) { - delete[] data; - data = 0; + delete[] owned_pixels; + pixels = owned_pixels = 0; fmt = other.fmt; width = other.width; height = other.height; stride = other.stride; - if(other.data) + if(other.pixels) { - data = new char[stride*height]; - copy(other.data, other.data+stride*height, data); + pixels = owned_pixels = new char[stride*height]; + copy(other.pixels, other.pixels+stride*height, pixels); } return *this; @@ -49,7 +51,7 @@ Image::Data &Image::Data::operator=(const Data &other) Image::Data::~Data() { - delete[] data; + delete[] owned_pixels; } @@ -67,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