From: Mikko Rasa Date: Mon, 13 Jul 2015 09:55:04 +0000 (+0300) Subject: Proper support for copying images X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=8e58f5bca4258e73e84e604ff2573fe9713b7b3f;p=libs%2Fgui.git Proper support for copying images --- diff --git a/source/graphics/image.cpp b/source/graphics/image.cpp index b22be19..a0e6e38 100644 --- a/source/graphics/image.cpp +++ b/source/graphics/image.cpp @@ -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; diff --git a/source/graphics/image.h b/source/graphics/image.h index 29fd288..9f17004 100644 --- a/source/graphics/image.h +++ b/source/graphics/image.h @@ -23,6 +23,8 @@ public: char *data; Data(); + Data(const Data &); + Data &operator=(const Data &); ~Data(); };