-
Notifications
You must be signed in to change notification settings - Fork 1
/
histogramwidget.h
109 lines (98 loc) · 3.92 KB
/
histogramwidget.h
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
/***********************************************************************
* FILENAME : histogramwidget.h
*
* LICENSE:
* qcvTouchUp provides an image processing toolset for editing
* photographs, purposed and packaged for use in a desktop application
* user environment. Copyright (C) 2018, Matthew R. Miller
*
* This program 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 (version 3 of the License) and the
* 3-clause BSD License as agreed upon through the use of the Qt toolkit
* and OpenCV libraries in qcvTouchUp development, respectively. Copies
* of the appropriate license files for qcvTouchup, and its source code,
* can be found in LICENSE.Qt.txt and LICENSE.CV.txt.
*
* This program 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 and
* 3-clause BSD License along with this program. If not, please see
* <http://www.gnu.org/licenses/> and <https://opencv.org/license.html>.
*
* If you wish to contact the developer about this project, please do so
* through their account at <https://github.com/mattrussmill>
*
* DESCRIPTION :
* This widget creates and manages a histogram plot of an image with
* either 1 or 3 channels and an 8 bit-depth per channel color depth.
* The histogram plot is drawn directly on the widget surface.
*
* NOTES :
* Be careful passing and manipulating a histogram buffer directly.
* Checks are not made regarding the buffer contents or if the buffer
* itself is of the correct size.
*
* 0.2 - Expanded to include static functionality such that members
* could be used to manipulate histogram buffers externally managed.
*
* AUTHOR : Matthew R. Miller START DATE : January 01/22/2018
*
* CHANGES : N/A - N/A
*
* VERSION DATE WHO DETAIL
* 0.1 02/19/2018 Matthew R. Miller Initial Rev
* 0.2 03/11/2018 Matthew R. Miller Notes 0.2
*
************************************************************************/
#ifndef HISTOGRAMWIDGET_H
#define HISTOGRAMWIDGET_H
#include <QWidget>
#include <QVector>
class QImage;
class QColor;
#define HISTO_SIZE 256
class HistogramWidget : public QWidget
{
Q_OBJECT
public:
enum HistogramChannel{Red = 0, Green = 1, Blue = 2};
explicit HistogramWidget(QWidget *parent = nullptr);
~HistogramWidget();
void setChannelColor(QColor color, HistogramChannel channel);
void setBackgroundColor(QColor color);
void clear();
void setLineWidth(float lineWidth = 2.5);
void setClickable(bool click);
bool isInitialized() const;
bool isClickable() const;
uint getLargestPeak() const;
int getNumberOfChannels() const;
uint** data() const;
void setNumberOfChannels(int numberOfChannels);
static void generateHistogram(QImage &image, uint** histogram, int numberOfChannels = 3);
signals:
void finished();
public slots:
void setHistogramData(const uint **data, int numberOfChannels);
void setHistogramData(const QImage &image);
protected:
void paintEvent(QPaintEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
private:
void calculatePoints();
uint **histogram_m;
QVector<QVector<QLineF>> points_m;
QVector<QColor> colors_m = {QColor(Qt::red), QColor(Qt::green), QColor(Qt::blue)};
QColor backgroundColor_m;
uint largestPeak_m;
int clickState_m = 0;
int channels_m = 3;
float penWidth_m = 2.5;
bool initialized_m = false;
bool clickable_m = false;
};
#endif // HISTOGRAMWIDGET_H