[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:
parent
6829814936
commit
2467bade73
|
@ -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; x<image->width(); x++) {
|
||||
for(int y=0; y<image->height(); 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();
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
#include <QSlider>
|
||||
#include <QColor>
|
||||
|
||||
#include <cmath>
|
||||
#include <math.h>
|
||||
#include "fstream"
|
||||
#include <iostream>
|
||||
|
||||
|
|
Loading…
Reference in New Issue