]> git.tdb.fi Git - libs/gui.git/blobdiff - source/graphics/image.cpp
Clear Image data before loading a new image
[libs/gui.git] / source / graphics / image.cpp
index 3e1124faaf06800158413189c054529db2ca4060..50e85dfe0981ca9b4ae1362d0de0fdc8439872f1 100644 (file)
@@ -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<ImageLoader> 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);
 }