-
Notifications
You must be signed in to change notification settings - Fork 0
/
curvedialog.cpp
157 lines (132 loc) · 5.13 KB
/
curvedialog.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include "curvedialog.h"
#include <QtWidgets>
CurveDialog::CurveDialog(QImage img)
: srcImage(img)
, viewImage(img)
, imageOp(new ImageOperations)
{
imageLabel = new QLabel;
imageLabel->setMaximumWidth(500);
QPixmap pix = QPixmap::fromImage(img);
qreal h = pix.height();
qreal w = pix.width();
pix = pix.scaled(500, 500 * h / w, Qt::KeepAspectRatio);
imageLabel->setPixmap(pix);
QVBoxLayout *imageLayout = new QVBoxLayout;
imageLayout->addWidget(imageLabel);
imageLayout->setContentsMargins(10, 10, 10, 10);
QGroupBox *imageGroup = new QGroupBox(tr("View Image"));
imageGroup->setLayout(imageLayout);
QRadioButton *linearBtn = new QRadioButton;
linearBtn->setText(tr("Linear Curve"));
linearBtn->setChecked(true);
QRadioButton *piecewiseLinBtn = new QRadioButton;
piecewiseLinBtn->setText(tr("Piecewise Linear Curve"));
QRadioButton *expBtn = new QRadioButton;
expBtn->setText(tr("Exponential Curve"));
QRadioButton *logBtn = new QRadioButton;
logBtn->setText(tr("Logarithm Curve"));
btnGroup = new QButtonGroup;
btnGroup->setExclusive(true);
btnGroup->addButton(linearBtn, 0);
btnGroup->addButton(piecewiseLinBtn, 1);
btnGroup->addButton(expBtn, 2);
btnGroup->addButton(logBtn, 3);
QHBoxLayout *curveLayout1 = new QHBoxLayout;
curveLayout1->addWidget(linearBtn);
curveLayout1->addWidget(piecewiseLinBtn);
QHBoxLayout *curveLayout2 = new QHBoxLayout;
curveLayout2->addWidget(logBtn);
curveLayout2->addWidget(expBtn);
QVBoxLayout *curveLayout = new QVBoxLayout;
curveLayout->addLayout(curveLayout1);
curveLayout->addLayout(curveLayout2);
curveLayout->setContentsMargins(10, 10, 10, 10);
QGroupBox *curveTypeBox = new QGroupBox(tr("Curve Type"));
curveTypeBox->setLayout(curveLayout);
canvas = new CurveCanvas(this, 256);
QVBoxLayout *curveViewLayout = new QVBoxLayout;
curveViewLayout->addWidget(canvas);
curveViewLayout->setContentsMargins(10, 10, 10, 10);
QGroupBox *curveViewBox = new QGroupBox(tr("Curve View"));
curveViewBox->setLayout(curveViewLayout);
QPushButton *applyButton = new QPushButton(tr("Apply"));
QPushButton *closeButton = new QPushButton(tr("Close"));
QHBoxLayout *btnLayout = new QHBoxLayout;
btnLayout->addStretch(1);
btnLayout->addWidget(applyButton);
btnLayout->addWidget(closeButton);
QVBoxLayout *settingLayout = new QVBoxLayout;
settingLayout->addWidget(curveTypeBox);
settingLayout->addWidget(curveViewBox);
settingLayout->addStretch(1);
settingLayout->addSpacing(12);
settingLayout->addLayout(btnLayout);
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addWidget(imageGroup);
mainLayout->addLayout(settingLayout);
setLayout(mainLayout);
connect(closeButton, &QAbstractButton::clicked, this, &QWidget::close);
connect(applyButton, &QAbstractButton::clicked, this, &CurveDialog::apply);
connect(btnGroup, SIGNAL(buttonClicked(int)), this, SLOT(curveTypeChanged(int)));
connect(canvas, SIGNAL(linearCurveChanged(QPoint,QPoint)), this,
SLOT(linearCurveChange(QPoint,QPoint)));
connect(canvas, SIGNAL(pieceLinCurveChanged(QPoint,QPoint)), this,
SLOT(pieceLinCurveChange(QPoint,QPoint)));
connect(canvas, SIGNAL(logCurveChanged(double,double)), this,
SLOT(logCurveChange(double,double)));
connect(canvas, SIGNAL(expCurveChanged(double,double)), this,
SLOT(expCurveChange(double,double)));
setWindowTitle(tr("Contrast Curve Dialog"));
}
void CurveDialog::apply(){
QJsonObject obj;
QString t;
CurveCanvas::CurveType type = (CurveCanvas::CurveType)btnGroup->checkedId();
switch(type){
case CurveCanvas::LINEAR:
t = "Linear";
break;
case CurveCanvas::PIECEWISE_LINEAR:
t = "Piecewice Linear";
break;
case CurveCanvas::LOGARITHM:
t = "Logarithm";
break;
case CurveCanvas::EXPONENTIAL:
t = "Exponential";
break;
default:
break;
}
obj.insert("type",t);
emit sendApplyCurve(obj, viewImage);
close();
}
void CurveDialog::logCurveChange(double a, double b){
QImage newImage = imageOp->logContrastAdjust(srcImage, a, b);
updateImage(newImage);
}
void CurveDialog::expCurveChange(double a, double b){
QImage newImage = imageOp->expContrastAdjust(srcImage, a, b);
updateImage(newImage);
}
void CurveDialog::linearCurveChange(QPoint p1, QPoint p2){
QImage newImage = imageOp->linearContrastAdjust(srcImage, p1.x(), p1.y(), p2.x(), p2.y());
updateImage(newImage);
}
void CurveDialog::pieceLinCurveChange(QPoint p1, QPoint p2){
QImage newImage = imageOp->pieceLinContrastAdjust(srcImage, p1.x(), p1.y(), p2.x(), p2.y());
updateImage(newImage);
}
void CurveDialog::curveTypeChanged(int index){
canvas->setType((CurveCanvas::CurveType)index);
}
void CurveDialog::updateImage(QImage &newImage){
viewImage = newImage;
QPixmap pix = QPixmap::fromImage(viewImage);
qreal h = pix.height();
qreal w = pix.width();
pix = pix.scaled(500, 500 * h / w, Qt::KeepAspectRatio);
imageLabel->setPixmap(pix);
}