From 1b71c572b9cb6f939a75ae2b64b35f53f37bcdcb Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Fri, 27 Nov 2015 15:06:21 +0100 Subject: [PATCH] [TASK] Add support for negative weights. --- imageviewer-qt4.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/imageviewer-qt4.cpp b/imageviewer-qt4.cpp index 5076d84..c060fda 100644 --- a/imageviewer-qt4.cpp +++ b/imageviewer-qt4.cpp @@ -487,8 +487,8 @@ void ImageViewer::applyBasicFilter() { for(int i=0; i " << current_data << std::endl; + filter_sum += abs(current_data); // support for negativ weights using abs() + logFile << "@" << i << "," << j << " -> " << current_data << std::endl; } } @@ -515,6 +515,9 @@ void ImageViewer::applyBasicFilter() { //std::cout << "old lightness: " << l << ", filter_sum: " << filter_sum << ", intensity_sum:" << intensity_sum; // divide by sum of weights l = qRound((intensity_sum*1.0) / filter_sum); + //optional clamping for exotic stuff like negative values + if(l > 255) l = 255; + if(l < 0) l = 0; //std::cout << " --> new l: " << l << std::endl; color.setHsl(h, s, l); // and set it.