[TASK] First try to implement contrast slider properly.

There seems to be something going wrong about loading
grayscaled images. This is to be fixed soon.
This commit is contained in:
Jan Philipp Timme 2015-11-06 23:16:41 +01:00
parent 6829814936
commit 2467bade73
2 changed files with 11 additions and 10 deletions

View File

@ -293,20 +293,21 @@ void ImageViewer::adjustBrightness(int b) {
void ImageViewer::adjustContrast(int c) { void ImageViewer::adjustContrast(int c) {
int h, s, old_l; int h, s, old_l;
int new_l = 0; int new_l = 0;
int delta = c - 255; double alpha = c / 255.0;
int average_intensity = getAverageIntensity();
for(int x=0; x<image->width(); x++) { for(int x=0; x<image->width(); x++) {
for(int y=0; y<image->height(); y++) { for(int y=0; y<image->height(); y++) {
// QColor color = QColor::fromRgb(original_image->pixel(x, y)); QColor color = QColor::fromRgb(original_image->pixel(x, y));
// color.getHsl(&h, &s, &old_l); color.getHsl(&h, &s, &old_l);
// new_l = old_l + delta; new_l = average_intensity + ((int) round((old_l - average_intensity) * alpha));
// if(new_l > 255) new_l = 255; if(new_l > 255) new_l = 255;
// if(new_l < 0) new_l = 0; if(new_l < 0) new_l = 0;
// color.setHsl(h, s, new_l); color.setHsl(h, s, new_l);
// image->setPixel(x, y, color.rgba()); image->setPixel(x, y, color.rgba());
} }
} }
updateImageDisplay(); 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(); renewLogging();
} }

View File

@ -49,7 +49,7 @@
#include <QSlider> #include <QSlider>
#include <QColor> #include <QColor>
#include <cmath> #include <math.h>
#include "fstream" #include "fstream"
#include <iostream> #include <iostream>