]> git.tdb.fi Git - libs/gui.git/commitdiff
Proper support for copying images
authorMikko Rasa <tdb@tdb.fi>
Mon, 13 Jul 2015 09:55:04 +0000 (12:55 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 13 Jul 2015 09:57:32 +0000 (12:57 +0300)
source/graphics/image.cpp
source/graphics/image.h

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;
index 29fd288c5634ca96a0b26c604b0cb56968ee89a3..9f170046a333880bcad995e2fbd3e0574b28e538 100644 (file)
@@ -23,6 +23,8 @@ public:
                char *data;
 
                Data();
+               Data(const Data &);
+               Data &operator=(const Data &);
                ~Data();
        };