From 8e58f5bca4258e73e84e604ff2573fe9713b7b3f Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 13 Jul 2015 12:55:04 +0300 Subject: [PATCH] Proper support for copying images --- source/graphics/image.cpp | 30 ++++++++++++++++++++++++++++++ source/graphics/image.h | 2 ++ 2 files changed, 32 insertions(+) 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(); }; -- 2.43.0