X-Git-Url: http://git.tdb.fi/?p=libs%2Fgui.git;a=blobdiff_plain;f=source%2Fgraphics%2Fimage.cpp;h=2835d05e872936d0cc069fa806812ff3ab952661;hp=fcfd222c165e7d6472fa4fdf4b6ea1c34d02ae68;hb=917c43de100807f4397e36b66b1a748dbf44370e;hpb=054fca09f0bbd64fdbd6406a0643de938a9cd4fb diff --git a/source/graphics/image.cpp b/source/graphics/image.cpp index fcfd222..2835d05 100644 --- a/source/graphics/image.cpp +++ b/source/graphics/image.cpp @@ -14,6 +14,7 @@ Image::Data::Data(): fmt(RGB), width(0), height(0), + owned_pixels(0), pixels(0) { } @@ -22,7 +23,8 @@ Image::Data::Data(const Data &other): width(other.width), height(other.height), stride(other.stride), - pixels(other.pixels ? new char[stride*height] : 0) + owned_pixels(other.pixels ? new char[stride*height] : 0), + pixels(owned_pixels) { if(pixels) copy(other.pixels, other.pixels+stride*height, pixels); @@ -30,8 +32,8 @@ Image::Data::Data(const Data &other): Image::Data &Image::Data::operator=(const Data &other) { - delete[] pixels; - pixels = 0; + delete[] owned_pixels; + pixels = owned_pixels = 0; fmt = other.fmt; width = other.width; @@ -40,7 +42,7 @@ Image::Data &Image::Data::operator=(const Data &other) if(other.pixels) { - pixels = new char[stride*height]; + pixels = owned_pixels = new char[stride*height]; copy(other.pixels, other.pixels+stride*height, pixels); } @@ -49,7 +51,7 @@ Image::Data &Image::Data::operator=(const Data &other) Image::Data::~Data() { - delete[] pixels; + delete[] owned_pixels; } @@ -72,6 +74,12 @@ void Image::load(ImageLoader &loader) 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)