]> git.tdb.fi Git - libs/gui.git/blobdiff - source/graphics/image.cpp
Proper support for copying images
[libs/gui.git] / source / graphics / image.cpp
index b22be1969d057e161cd60af0be3d9785c320b438..a0e6e380ad24d54b20c5144c6001208147f9dbc5 100644 (file)
@@ -17,6 +17,36 @@ Image::Data::Data():
        data(0)
 { }
 
+Image::Data::Data(const Data &other):
+       fmt(other.fmt),
+       width(other.width),
+       height(other.height),
+       stride(other.stride),
+       data(other.data ? new char[stride*height] : 0)
+{
+       if(data)
+               copy(other.data, other.data+stride*height, data);
+}
+
+Image::Data &Image::Data::operator=(const Data &other)
+{
+       delete[] data;
+       data = 0;
+
+       fmt = other.fmt;
+       width = other.width;
+       height = other.height;
+       stride = other.stride;
+
+       if(other.data)
+       {
+               data = new char[stride*height];
+               copy(other.data, other.data+stride*height, data);
+       }
+
+       return *this;
+}
+
 Image::Data::~Data()
 {
        delete[] data;