From ab7ab9e52ab87963831f90ab25957d883878654d Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 2 Jun 2016 21:00:37 +0200 Subject: New ImageCache class for reusing Image resources. --- plugingui/image.cc | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'plugingui/image.cc') diff --git a/plugingui/image.cc b/plugingui/image.cc index 250dc60..63f708d 100644 --- a/plugingui/image.cc +++ b/plugingui/image.cc @@ -48,9 +48,39 @@ Image::Image(const std::string& filename) load(rc.data(), rc.size()); } +Image::Image(Image&& other) + : _width(other._width) + , _height(other._height) + , image_data(other.image_data) +{ + other.image_data = nullptr; + other._width = 0; + other._height = 0; +} + Image::~Image() { - std::free(image_data); + if(image_data) + { + std::free(image_data); + } +} + +Image& Image::operator=(Image&& other) +{ + if(image_data) + { + std::free(image_data); + } + image_data = other.image_data; + _width = other._width; + _height = other._height; + + other.image_data = nullptr; + other._width = 0; + other._height = 0; + + return *this; } void Image::setError() -- cgit v1.2.3