forked from jcelaya/hdrmerge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
PreviewWidget.hpp
118 lines (103 loc) · 3.1 KB
/
PreviewWidget.hpp
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
/*
* HDRMerge - HDR exposure merging software.
* Copyright 2012 Javier Celaya
*
* This file is part of HDRMerge.
*
* HDRMerge is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HDRMerge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HDRMerge. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef _PREVIEWWIDGET_H_
#define _PREVIEWWIDGET_H_
#include <memory>
#include <list>
#include <QWidget>
#include <QPaintEvent>
#include <QFuture>
#include "ImageStack.hpp"
namespace hdrmerge {
class PreviewWidget : public QWidget {
public:
static const int maxRadius = 200;
PreviewWidget(ImageStack & s, QWidget * parent);
QSize sizeHint() const;
static QRgb getColor(int layer, int v);
public slots:
void reload();
void toggleAddPixelsTool(bool toggled) {
addPixels = toggled;
setShowBrush();
}
void toggleRmPixelsTool(bool toggled) {
rmPixels = toggled;
setShowBrush();
}
void selectLayer(int i) { layer = i; }
void setRadius(int r) {
radius = r;
if (radius < 0) radius = 0;
if (radius > maxRadius) radius = maxRadius;
setShowBrush();
}
void setExposureMultiplier(int e) {
if (stack.size() > 0) {
expMult = 1.0 + e * stack.getMaxExposure() / (stack.size() * 1000.0);
repaintAsync();
}
}
void undo();
void redo();
signals:
void radiusChanged(int r);
void pixelUnderMouse(int x, int y);
protected:
void paintEvent(QPaintEvent * event);
void mousePressEvent(QMouseEvent * event) { mouseEvent(event, true); }
void mouseMoveEvent(QMouseEvent * event) { mouseEvent(event, false); }
void mouseEvent(QMouseEvent * event, bool pressed);
void wheelEvent(QWheelEvent * event);
void enterEvent(QEvent * event) { update(); }
void leaveEvent(QEvent * event) { update(); }
private slots:
void paintImage(QPoint where, const QImage & image);
private:
Q_OBJECT
std::unique_ptr<QPixmap> pixmap;
ImageStack & stack;
size_t width, height;
int flip;
bool addPixels, rmPixels;
int layer;
int radius;
int mouseX, mouseY;
QPixmap brush;
double expMult;
QFuture<void> currentRender;
bool cancelRender;
uint8_t gamma[65536];
void render(QRect zone);
QRgb rgb(int col, int row) const;
void rotate(int & x, int & y) const;
QPoint unrotate(QPoint p) const {
int x = p.x(), y = p.y();
rotate(x, y); rotate(x, y); rotate(x, y);
return QPoint(x, y);
}
void createBrush(bool plus);
void setShowBrush();
void repaintAsync();
};
} // namespace hdrmerge
#endif // _PREVIEWWIDGET_H_