From ca4a13c757efb08fe4765485e360839d413fc3bb Mon Sep 17 00:00:00 2001 From: spillerrec Date: Sat, 17 Oct 2015 21:12:17 +0200 Subject: [PATCH] FIX: Crash on duplicate images, but some of the methods in Image needs review. #3 --- src/Image.cpp | 18 +++++++++++++----- src/Image.hpp | 4 ++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Image.cpp b/src/Image.cpp index 0de2c18..beb7bfc 100644 --- a/src/Image.cpp +++ b/src/Image.cpp @@ -33,6 +33,18 @@ const auto PIXEL_DIFFERENT = 0; //Pixel do not match with other image const auto PIXEL_MATCH = 1; //Pixel is the same as other image const auto PIXEL_SHARED = 2; //Pixel is the same, but must not be set as it differ in another image +static QImage make_mask( QSize size ){ + QImage mask( size, QImage::Format_Indexed8 ); + mask.setColor( PIXEL_MATCH, qRgb(255, 0, 0) ); + mask.setColor( PIXEL_DIFFERENT, qRgb(0, 255, 0) ); + mask.setColor( PIXEL_SHARED, qRgb(0, 0, 255) ); + return mask; +} + +Image::Image( QPoint pos, QImage img ) : pos(pos), img(img), mask(make_mask(img.size())) { + mask.fill( PIXEL_DIFFERENT ); +} + /** Create a resized version of this image, will keep aspect ratio * \param [in] size Maximum dimensions of the resized image * \return The resized image */ @@ -170,11 +182,7 @@ Image Image::combine( Image on_top ) const{ Image Image::difference( Image input ) const{ //TODO: images must be the same size and at same point - QImage mask( img.size(), QImage::Format_Indexed8 ); - mask.setColor( PIXEL_MATCH, qRgb(255, 0, 0) ); - mask.setColor( PIXEL_DIFFERENT, qRgb(0, 255, 0) ); - mask.setColor( PIXEL_SHARED, qRgb(0, 0, 255) ); - + auto mask = make_mask( img.size() ); for( int iy=0; iy