From dc2f0e3490e37cb388acf60d3db90dd90f5ae451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Poizl?= Date: Thu, 23 Jan 2020 13:22:47 +0100 Subject: [PATCH] Live mode --- clahe.cpp | 5 +++++ clahe.h | 1 + mainwindow.cpp | 22 ++++++++++++++++++---- mainwindow.h | 2 ++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/clahe.cpp b/clahe.cpp index f56c8ff..1a833d4 100644 --- a/clahe.cpp +++ b/clahe.cpp @@ -56,3 +56,8 @@ QPixmap CLAHE::getLumImage() const QImage ret(tmp.data, tmp.cols, tmp.rows, tmp.step1(), QImage::Format_Grayscale8); return QPixmap::fromImage(ret); } + +bool CLAHE::imageLoaded() const +{ + return _lumImage.ptr(); +} diff --git a/clahe.h b/clahe.h index 07830d6..ed3fc10 100644 --- a/clahe.h +++ b/clahe.h @@ -19,6 +19,7 @@ public: void apply(float clipLimit, int kernelSize); QPixmap getImage() const; QPixmap getLumImage() const; + bool imageLoaded() const; }; #endif // CLAHE_H diff --git a/mainwindow.cpp b/mainwindow.cpp index 380f34c..7aae2fb 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -45,10 +45,19 @@ void MainWindow::saveFile() void MainWindow::applyClahe() { - QPixmap pixmap; - _clahe->apply(_clipLimitSlider->value()/100.0f, _kernelSizeSelect->currentText().toInt()); - pixmap = _clahe->getImage(); - _imageScrollArea->setImage(pixmap); + if(_clahe->imageLoaded()) + { + QPixmap pixmap; + _clahe->apply(_clipLimitSlider->value()/100.0f, _kernelSizeSelect->currentText().toInt()); + pixmap = _clahe->getImage(); + _imageScrollArea->setImage(pixmap); + } +} + +void MainWindow::applyLive() +{ + if(_liveApply->isChecked()) + applyClahe(); } void MainWindow::setupUI() @@ -58,6 +67,9 @@ void MainWindow::setupUI() QMenu *fileMenu = menuBar()->addMenu(tr("File")); fileMenu->addAction(tr("Open file"), this, SLOT(openFile()), QKeySequence("Ctrl+O")); fileMenu->addAction(tr("Save file"), this, SLOT(saveFile()), QKeySequence("Ctrl+S")); + _liveApply = fileMenu->addAction(tr("Live mode")); + _liveApply->setCheckable(true); + _liveApply->setChecked(true); fileMenu->addAction(tr("Quit"), this, SLOT(close()), QKeySequence("Ctrl+Q")); _clipLimitEdit = new QLineEdit; @@ -75,6 +87,7 @@ void MainWindow::setupUI() _kernelSizeSelect = new QComboBox; _kernelSizeSelect->addItems({"8", "16", "32", "64", "128", "256"}); + connect(_kernelSizeSelect, SIGNAL(currentIndexChanged(int)), this, SLOT(applyLive())); QHBoxLayout *claheLayout = new QHBoxLayout; claheLayout->addWidget(_clipLimitEdit); @@ -95,4 +108,5 @@ void MainWindow::setupUI() void MainWindow::clipSliderValueChanged(int value) { _clipLimitEdit->setText(QString::number(value/100.0)); + applyLive(); } diff --git a/mainwindow.h b/mainwindow.h index ecf02dd..7963037 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -15,6 +15,7 @@ class MainWindow : public QMainWindow QLineEdit *_clipLimitEdit; CLAHE *_clahe; ImageScrollArea *_imageScrollArea; + QAction *_liveApply; public: explicit MainWindow(QWidget *parent = nullptr); ~MainWindow(); @@ -22,6 +23,7 @@ public slots: void openFile(); void saveFile(); void applyClahe(); + void applyLive(); private: void setupUI(); private slots: