-
Notifications
You must be signed in to change notification settings - Fork 9
/
mainwindow.cpp
74 lines (59 loc) · 1.93 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
offset = ui->spinBoxOffset->value();
iterations = ui->spinBoxIterations->value();
originalImage = QImage(":/img/lenna.png");
updateShownImage();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_buttonOpenFile_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Open Image"), "", tr("Image Files (*.png *.jpg *.bmp)"));
if (!fileName.isEmpty()) {
QImageReader reader(fileName);
if (reader.canRead()) {
originalImage = QImage(fileName);
updateShownImage();
}
}
}
void MainWindow::resizeEvent(QResizeEvent *event)
{
QMainWindow::resizeEvent(event);
updateShownImage();
}
void MainWindow::on_spinBoxOffset_valueChanged(int arg1)
{
offset = arg1;
showBlurredImage();
}
void MainWindow::on_spinBoxIterations_valueChanged(int arg1)
{
iterations = arg1;
showBlurredImage();
}
void MainWindow::updateShownImage()
{
shownImage = originalImage.scaled(ui->labelBlurredImage->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
showBlurredImage();
QString textureSize(QString::number(shownImage.size().width()) + "x" + QString::number(shownImage.size().height()));
ui->labelTextureSize->setText(textureSize);
}
void MainWindow::showBlurredImage()
{
if (iterations == 0) {
ui->labelBlurredImage->setPixmap(QPixmap::fromImage(shownImage));
return;
}
ui->labelBlurredImage->setPixmap(QPixmap::fromImage(GLBlurDualKawase.blurImage_DualKawase(shownImage, offset, iterations)));
ui->labelGPUTime->setText(QString::number(GLBlurDualKawase.getGPUTime()) + " ms");
ui->labelCPUTime->setText(QString::number(GLBlurDualKawase.getCPUTime()) + " ms");
}