diff --git a/imageviewer-qt4.cpp b/imageviewer-qt4.cpp index b94d70b..0e7b023 100644 --- a/imageviewer-qt4.cpp +++ b/imageviewer-qt4.cpp @@ -73,6 +73,31 @@ void ImageViewer::initializeImage() { analyzeImage(); } +/** + * In case it is needed, convert the loaded image into grayscale. + * @brief ImageViewer::convertToMonochrome + */ +void ImageViewer::convertToMonochrome() { + if(image!=NULL) { + logFile << "Converting image to monochrome..."; + renewLogging(); + for(int x=0; xwidth(); x++) { + for(int y=0; yheight(); y++) { + int r,g,b; + QColor color = QColor::fromRgb(image->pixel(x, y)); + color.getRgb(&r,&g,&b); + int intensity = (int)(0.299*r+0.587*g+0.114*b); + color = QColor::fromRgb(intensity, intensity, intensity); + image->setPixel(x, y, color.rgba()); + original_image->setPixel(x, y, color.rgba()); + } + } + updateImageDisplay(); + logFile << "done." << std::endl; + renewLogging(); + } +} + /** * Draws a simple, black line. @@ -195,7 +220,7 @@ void ImageViewer::analyzeImage() { renewLogging(); QString result = QString("Intensity: Average: %1, Variance: %2").arg(getAverageIntensity()).arg(getIntensityVariance()); - task_tab2_stats->setText(result); + stats->setText(result); updateHistogramm(); } @@ -324,21 +349,25 @@ void ImageViewer::generateControlPanels() { task_tab1 = new QVBoxLayout(); task_tab_widget1->setLayout(task_tab1); - task_tab1_button1 = new QPushButton(); - task_tab1_button1->setText("Draw a black line"); - QObject::connect(task_tab1_button1, SIGNAL(clicked()), this, SLOT (drawBlackLine())); + monochrome = new QPushButton(); + monochrome->setText("Convert to monochrome"); + QObject::connect(monochrome, SIGNAL(clicked()), this, SLOT (convertToMonochrome())); + + draw_black_line = new QPushButton(); + draw_black_line->setText("Draw a black line"); + QObject::connect(draw_black_line, SIGNAL(clicked()), this, SLOT (drawBlackLine())); - task_tab1_button2 = new QPushButton(); - task_tab1_button2->setText("Draw a rainbow cross"); - QObject::connect(task_tab1_button2, SIGNAL(clicked()), this, SLOT (drawRainbowCross())); + draw_rainbow_cross = new QPushButton(); + draw_rainbow_cross->setText("Draw a rainbow cross"); + QObject::connect(draw_rainbow_cross, SIGNAL(clicked()), this, SLOT (drawRainbowCross())); - task_tab1_button3 = new QPushButton(); - task_tab1_button3->setText("Start the neverending acid trip!"); - QObject::connect(task_tab1_button3, SIGNAL(clicked()), this, SLOT (acidTrippin())); + acid_trip = new QPushButton(); + acid_trip->setText("Start the neverending acid trip!"); + QObject::connect(acid_trip, SIGNAL(clicked()), this, SLOT (acidTrippin())); - task_tab1_button4 = new QPushButton(); - task_tab1_button4->setText("Draw a diagonal cross"); - QObject::connect(task_tab1_button4, SIGNAL(clicked()), this, SLOT (drawDiagonalCross())); + diagonal_cross = new QPushButton(); + diagonal_cross->setText("Draw a diagonal cross"); + QObject::connect(diagonal_cross, SIGNAL(clicked()), this, SLOT (drawDiagonalCross())); line_slider = new QSlider(Qt::Horizontal); line_slider->setMinimum(1); @@ -346,11 +375,12 @@ void ImageViewer::generateControlPanels() { line_slider->setValue(3); //QObject::connect(lineSlider, SIGNAL(valueChanged(int)), this, SLOT (drawRainbowCross())); + task_tab1->addWidget(monochrome); task_tab1->addWidget(new QLabel("Let's draw something!")); - task_tab1->addWidget(task_tab1_button1); - task_tab1->addWidget(task_tab1_button2); - task_tab1->addWidget(task_tab1_button3); - task_tab1->addWidget(task_tab1_button4); + task_tab1->addWidget(draw_black_line); + task_tab1->addWidget(draw_rainbow_cross); + task_tab1->addWidget(acid_trip); + task_tab1->addWidget(diagonal_cross); task_tab1->addWidget(new QLabel("This will not stop unless process is killed.")); task_tab1->addWidget(line_slider); task_tab1->addWidget(new QLabel("Sets the width of the cross.")); @@ -368,9 +398,13 @@ void ImageViewer::generateControlPanels() { histogramm_label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); histogramm_label->setScaledContents(false); - task_tab2_stats = new QLabel(); - task_tab2_stats->setText("Intensity will be shown here."); + stats = new QLabel(); + stats->setText("Intensity will be shown here."); + analyze_image = new QPushButton(); + analyze_image->setText("Analyze image"); + QObject::connect(analyze_image, SIGNAL(clicked()), this, SLOT(analyzeImage())); + brightness_slider = new QSlider(Qt::Horizontal); brightness_slider->setMinimum(0); brightness_slider->setMaximum(510); @@ -383,9 +417,10 @@ void ImageViewer::generateControlPanels() { contrast_slider->setValue(255); QObject::connect(contrast_slider, SIGNAL(valueChanged(int)), this, SLOT (adjustContrast(int))); - task_tab2->addWidget(task_tab2_stats); + task_tab2->addWidget(stats); task_tab2->addWidget(new QLabel("Histogramm")); task_tab2->addWidget(histogramm_label); + task_tab2->addWidget(analyze_image); task_tab2->addWidget(new QLabel("Brightness")); task_tab2->addWidget(brightness_slider); task_tab2->addWidget(new QLabel("Contrast")); diff --git a/imageviewer-qt4.h b/imageviewer-qt4.h index 7075eb5..ce7b639 100644 --- a/imageviewer-qt4.h +++ b/imageviewer-qt4.h @@ -72,10 +72,12 @@ class ImageViewer : public QMainWindow { QWidget* task_tab_widget1; QVBoxLayout* task_tab1; - QPushButton* task_tab1_button1; - QPushButton* task_tab1_button2; - QPushButton* task_tab1_button3; - QPushButton* task_tab1_button4; + QPushButton* draw_black_line; + QPushButton* draw_rainbow_cross; + QPushButton* acid_trip; + QPushButton* diagonal_cross; + QPushButton* monochrome; + QSlider* line_slider; @@ -83,8 +85,9 @@ class ImageViewer : public QMainWindow { QWidget* task_tab_widget2; QVBoxLayout* task_tab2; - QLabel* task_tab2_stats; + QLabel* stats; QLabel* histogramm_label; + QPushButton* analyze_image; QSlider* brightness_slider; QSlider* contrast_slider; @@ -109,6 +112,7 @@ class ImageViewer : public QMainWindow { void updateHistogramm(); void adjustBrightness(int b); void adjustContrast(int c); + void convertToMonochrome(); void open(); void print();