X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgraphics%2Fimage.cpp;h=50e85dfe0981ca9b4ae1362d0de0fdc8439872f1;hb=d9ab515e15166fe88ff45970263616d05d340e3e;hp=3e1124faaf06800158413189c054529db2ca4060;hpb=cfd3548464e6424fc9decf0539d6cd04b031ba10;p=libs%2Fgui.git diff --git a/source/graphics/image.cpp b/source/graphics/image.cpp index 3e1124f..50e85df 100644 --- a/source/graphics/image.cpp +++ b/source/graphics/image.cpp @@ -14,12 +14,42 @@ Image::Data::Data(): fmt(RGB), width(0), height(0), - data(0) + pixels(0) { } +Image::Data::Data(const Data &other): + fmt(other.fmt), + width(other.width), + height(other.height), + stride(other.stride), + pixels(other.pixels ? new char[stride*height] : 0) +{ + if(pixels) + copy(other.pixels, other.pixels+stride*height, pixels); +} + +Image::Data &Image::Data::operator=(const Data &other) +{ + delete[] pixels; + pixels = 0; + + fmt = other.fmt; + width = other.width; + height = other.height; + stride = other.stride; + + if(other.pixels) + { + pixels = new char[stride*height]; + copy(other.pixels, other.pixels+stride*height, pixels); + } + + return *this; +} + Image::Data::~Data() { - delete[] data; + delete[] pixels; } @@ -29,7 +59,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,6 +67,7 @@ void Image::load_io(IO::Base &io) void Image::load(ImageLoader &loader) { + data = Data(); loader.load(data); }