diff --git a/imageviewer-qt4.cpp b/imageviewer-qt4.cpp index 972da2e..b94d70b 100644 --- a/imageviewer-qt4.cpp +++ b/imageviewer-qt4.cpp @@ -293,20 +293,21 @@ void ImageViewer::adjustBrightness(int b) { void ImageViewer::adjustContrast(int c) { int h, s, old_l; int new_l = 0; - int delta = c - 255; + double alpha = c / 255.0; + int average_intensity = getAverageIntensity(); for(int x=0; xwidth(); x++) { for(int y=0; yheight(); y++) { -// QColor color = QColor::fromRgb(original_image->pixel(x, y)); -// color.getHsl(&h, &s, &old_l); -// new_l = old_l + delta; -// if(new_l > 255) new_l = 255; -// if(new_l < 0) new_l = 0; -// color.setHsl(h, s, new_l); -// image->setPixel(x, y, color.rgba()); + QColor color = QColor::fromRgb(original_image->pixel(x, y)); + color.getHsl(&h, &s, &old_l); + new_l = average_intensity + ((int) round((old_l - average_intensity) * alpha)); + if(new_l > 255) new_l = 255; + if(new_l < 0) new_l = 0; + color.setHsl(h, s, new_l); + image->setPixel(x, y, color.rgba()); } } updateImageDisplay(); - logFile << "[TODO!] Contrast adjusted to: " << old_l << " + " << delta << " -> (" << h << ", " << s << ", " << new_l << ")" << std::endl; + logFile << "[TODO!] Contrast adjusted to: " << old_l << " * " << alpha << " -> (" << h << ", " << s << ", " << new_l << ")" << std::endl; renewLogging(); } diff --git a/imageviewer-qt4.h b/imageviewer-qt4.h index 243758b..7075eb5 100644 --- a/imageviewer-qt4.h +++ b/imageviewer-qt4.h @@ -49,7 +49,7 @@ #include #include -#include +#include #include "fstream" #include