[TASK] Add support for negative weights.

This commit is contained in:
Jan Philipp Timme 2015-11-27 15:06:21 +01:00
parent f875f1b8b6
commit 1b71c572b9

View File

@ -487,8 +487,8 @@ void ImageViewer::applyBasicFilter() {
for(int i=0; i<filter_size; i++) { for(int i=0; i<filter_size; i++) {
for(int j=0; j<filter_size; j++) { for(int j=0; j<filter_size; j++) {
int current_data = data[i*filter_size + j]; int current_data = data[i*filter_size + j];
filter_sum += current_data; filter_sum += abs(current_data); // support for negativ weights using abs()
//logFile << "@" << i << "," << j << " -> " << current_data << std::endl; 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; //std::cout << "old lightness: " << l << ", filter_sum: " << filter_sum << ", intensity_sum:" << intensity_sum;
// divide by sum of weights // divide by sum of weights
l = qRound((intensity_sum*1.0) / filter_sum); 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; //std::cout << " --> new l: " << l << std::endl;
color.setHsl(h, s, l); color.setHsl(h, s, l);
// and set it. // and set it.