[TASK] Implement brightness slider logic.
This commit is contained in:
parent
352fc1cf80
commit
99f6b596a1
|
@ -45,8 +45,9 @@
|
|||
* @brief ImageViewer::ImageViewer
|
||||
*/
|
||||
ImageViewer::ImageViewer() {
|
||||
image=NULL;
|
||||
histogramm=NULL;
|
||||
original_image = NULL;
|
||||
image = NULL;
|
||||
histogramm = NULL;
|
||||
startLogging();
|
||||
generateMainGui();
|
||||
renewLogging();
|
||||
|
@ -56,6 +57,23 @@ ImageViewer::ImageViewer() {
|
|||
resize(1600, 600);
|
||||
}
|
||||
|
||||
/**
|
||||
* Once an image is loaded, automatically perform these operations.
|
||||
*
|
||||
* analyze the image
|
||||
* allocate brightness map
|
||||
*
|
||||
* @brief ImageViewer::initializeImage
|
||||
*/
|
||||
void ImageViewer::initializeImage() {
|
||||
if(image==NULL) {
|
||||
std::cout << "Error! No image provided!" << std::endl;
|
||||
return;
|
||||
}
|
||||
analyzeImage();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draws a simple, black line.
|
||||
* @brief ImageViewer::drawBlackLine
|
||||
|
@ -176,7 +194,7 @@ void ImageViewer::analyzeImage() {
|
|||
logFile << "done" << std::endl;
|
||||
renewLogging();
|
||||
|
||||
QString result = QString("Intensity - average : %1, variance: %2").arg(getAverageIntensity()).arg(getIntensityVariance());
|
||||
QString result = QString("Intensity: Average: %1, Variance: %2").arg(getAverageIntensity()).arg(getIntensityVariance());
|
||||
task_tab2_stats->setText(result);
|
||||
|
||||
updateHistogramm();
|
||||
|
@ -244,6 +262,30 @@ void ImageViewer::updateHistogramm() {
|
|||
histogramm_label->setPixmap(QPixmap::fromImage(*histogramm));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired by the brightness_slider, this one adjusts the brightness on image.
|
||||
* @brief ImageViewer::adjustBrightness
|
||||
*/
|
||||
void ImageViewer::adjustBrightness(int b) {
|
||||
int h, s, old_l;
|
||||
int new_l = 0;
|
||||
int delta = b - 255;
|
||||
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());
|
||||
}
|
||||
}
|
||||
updateImageDisplay();
|
||||
logFile << "Brightness adjusted to: " << old_l << " + " << delta << " -> (" << h << ", " << s << ", " << new_l << ")" << std::endl;
|
||||
renewLogging();
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
* GUI elements related to the tasks are set up here.
|
||||
|
@ -294,14 +336,10 @@ void ImageViewer::generateControlPanels() {
|
|||
task_tab_widget2 = new QWidget();
|
||||
task_tab2 = new QVBoxLayout();
|
||||
task_tab_widget2->setLayout(task_tab2);
|
||||
|
||||
task_tab2_button1 = new QPushButton();
|
||||
task_tab2_button1->setText("Analyze image");
|
||||
QObject::connect(task_tab2_button1, SIGNAL(clicked()), this, SLOT (analyzeImage()));
|
||||
|
||||
|
||||
histogramm_label = new QLabel();
|
||||
histogramm_label->setBackgroundRole(QPalette::Base);
|
||||
histogramm_label->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
|
||||
histogramm_label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
histogramm_label->setScaledContents(false);
|
||||
|
||||
task_tab2_stats = new QLabel();
|
||||
|
@ -309,15 +347,15 @@ void ImageViewer::generateControlPanels() {
|
|||
|
||||
brightness_slider = new QSlider(Qt::Horizontal);
|
||||
brightness_slider->setMinimum(0);
|
||||
brightness_slider->setMaximum(255);
|
||||
brightness_slider->setValue(127);
|
||||
brightness_slider->setMaximum(510);
|
||||
brightness_slider->setValue(255);
|
||||
QObject::connect(brightness_slider, SIGNAL(valueChanged(int)), this, SLOT (adjustBrightness(int)));
|
||||
|
||||
contrast_slider = new QSlider(Qt::Horizontal);
|
||||
contrast_slider->setMinimum(0);
|
||||
contrast_slider->setMaximum(255);
|
||||
contrast_slider->setValue(127);
|
||||
|
||||
task_tab2->addWidget(task_tab2_button1);
|
||||
|
||||
task_tab2->addWidget(task_tab2_stats);
|
||||
task_tab2->addWidget(new QLabel("Histogramm"));
|
||||
task_tab2->addWidget(histogramm_label);
|
||||
|
@ -344,7 +382,7 @@ void ImageViewer::generateControlPanels() {
|
|||
|
||||
/****************************************************************************************
|
||||
*
|
||||
* The following methods are about the generic image viewer application and do not contain
|
||||
* The following methods are about the adjustBrightness(int)generic image viewer application and do not contain
|
||||
* any special graphics logic.
|
||||
*
|
||||
*****************************************************************************************/
|
||||
|
@ -442,8 +480,13 @@ void ImageViewer::open() {
|
|||
if(image->isNull()) {
|
||||
QMessageBox::information(this, tr("Image Viewer"), tr("Cannot load %1.").arg(fileName));
|
||||
return;
|
||||
} else {
|
||||
if(original_image!=NULL) {
|
||||
delete original_image;
|
||||
original_image = NULL;
|
||||
}
|
||||
original_image = new QImage(fileName);
|
||||
}
|
||||
|
||||
scaleFactor = 1.0;
|
||||
updateImageDisplay();
|
||||
printAct->setEnabled(true);
|
||||
|
@ -453,6 +496,7 @@ void ImageViewer::open() {
|
|||
setWindowFilePath(fileName);
|
||||
logFile << "geladen: " << fileName.toStdString().c_str() << std::endl;
|
||||
renewLogging();
|
||||
initializeImage(); //Now hook to prepare certain datastructures after loading.
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
|
||||
#include <cmath>
|
||||
#include "fstream"
|
||||
#include <iostream>
|
||||
|
||||
class QAction;
|
||||
class QLabel;
|
||||
|
@ -82,7 +83,6 @@ class ImageViewer : public QMainWindow {
|
|||
QWidget* task_tab_widget2;
|
||||
QVBoxLayout* task_tab2;
|
||||
|
||||
QPushButton* task_tab2_button1;
|
||||
QLabel* task_tab2_stats;
|
||||
QLabel* histogramm_label;
|
||||
|
||||
|
@ -95,8 +95,9 @@ class ImageViewer : public QMainWindow {
|
|||
|
||||
// "My" space for storing data/results
|
||||
int grayscale_absolute_histogramm[256];
|
||||
double grayscale_relative_histogramm[256];
|
||||
double grayscale_relative_histogramm[256];
|
||||
QImage* histogramm;
|
||||
QImage* original_image;
|
||||
|
||||
private slots:
|
||||
// Custom slots
|
||||
|
@ -106,6 +107,7 @@ class ImageViewer : public QMainWindow {
|
|||
void acidTrippin();
|
||||
void analyzeImage();
|
||||
void updateHistogramm();
|
||||
void adjustBrightness(int b);
|
||||
|
||||
void open();
|
||||
void print();
|
||||
|
@ -128,7 +130,7 @@ class ImageViewer : public QMainWindow {
|
|||
void drawRainbowCross(int h);
|
||||
int getAverageIntensity();
|
||||
int getIntensityVariance();
|
||||
|
||||
|
||||
void generateControlPanels();
|
||||
void startLogging();
|
||||
void generateMainGui();
|
||||
|
@ -138,6 +140,7 @@ class ImageViewer : public QMainWindow {
|
|||
void scaleImage(double factor);
|
||||
void adjustScrollBar(QScrollBar *scrollBar, double factor);
|
||||
|
||||
void initializeImage();
|
||||
void renewLogging();
|
||||
|
||||
QTabWidget* tabWidget;
|
||||
|
|
Loading…
Reference in New Issue