-
Notifications
You must be signed in to change notification settings - Fork 0
/
imwidget.cpp
181 lines (158 loc) · 4.09 KB
/
imwidget.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include "imwidget.h"
Imwidget::Imwidget(QWidget *parent) : QWidget(parent)
{
qim = 0L ;
qim_0 = 0l;
qim_1 = 0l ;
userFlag = false ;
uMax = 32768 ; ;
uMin = 0 ;
imageLoaded = false ;
nightFlag = true ;
xloc = 0 ;
yloc = 0 ;
}
Imwidget::~Imwidget(){
if (qim_0)
delete qim_0 ;
if (qim_1)
delete qim_1 ;
}
void Imwidget::setXY (int x, int y){
xloc = x ;
yloc = y ;
update() ;
}
void Imwidget::loadQImage (unsigned short *dat, int ns, int nl) {
int i, npix ;
float fval, scale, off ;
float min, max, mnmx[2] ;
QRgb *line ;
if (qim_0) delete qim_0 ;
qim_0 = new QImage (ns, nl, QImage::Format_ARGB32) ;
unsigned char cbyte ;
min=1.E9 ;
max=-1.E9 ;
npix = nl * ns ;
if (userFlag) {
max = uMax ;
min = uMin ;
} else {
for (i=0; i<npix; i++){
fval = *(dat+i) ;
if (fval <=0) continue ;
if (fval > max) max = fval ;
if (fval< min) min = fval ;
}
mnmx[0] = min ;
mnmx[1] = max ;
uMax = max ;
uMin = min ;
//emit (setMnMx ((float*)&mnmx[0])) ;
}
//max = 10000 ;
//min = 0 ;
qDebug () << "Min max is : "<< min << " " << max ;
scale = 255. / (max - min) ;
for (i=0; i<nl; i++){
line = (QRgb *) qim_0->scanLine(i) ;
for (int j=0; j<ns; j++){
fval = *(dat+i*ns+j) ;
fval = ((fval - min) * scale) ;
if (fval < 0.) fval = 0. ;
if (fval >255.) fval = 255. ;
cbyte = (unsigned char)fval ;
*(line+j) = qRgb ( cbyte, cbyte, cbyte) ;
}
}
imageLoaded = true ;
qim = qim_0 ;
}
/**
* @brief Imwidget::loadQImage_alt - create qimage which is the daytime LST file for this app
* @param dat UInt16* image data
* @param ns Int number of samples
* @param nl Int number of lines
*/
void Imwidget::loadQImage_alt (unsigned short *dat, int ns, int nl) {
int i, npix ;
float fval, scale, off ;
float min, max, mnmx[2] ;
QRgb *line ;
if (qim_1) delete qim_1 ;
qim_1 = new QImage (ns, nl, QImage::Format_ARGB32) ;
unsigned char cbyte ;
min=1.E9 ;
max=-1.E9 ;
npix = nl * ns ;
if (userFlag) {
max = uMax ;
min = uMin ;
} else {
for (i=0; i<npix; i++){
fval = *(dat+i) ;
if (fval <=0) continue ;
if (fval > max) max = fval ;
if (fval< min) min = fval ;
}
mnmx[0] = min ;
mnmx[1] = max ;
uMax = max ;
uMin = min ;
//emit (setMnMx ((float*)&mnmx[0])) ;
}
scale = 255. / (max - min) ;
for (i=0; i<nl; i++){
line = (QRgb *) qim_1->scanLine(i) ;
for (int j=0; j<ns; j++){
fval = *(dat+i*ns+j) ;
fval = ((fval - min) * scale) ;
if (fval < 0.) fval = 0. ;
if (fval >255.) fval = 255. ;
cbyte = (unsigned char)fval ;
*(line+j) = qRgb ( cbyte, cbyte, cbyte) ;
}
}
}
/**
* @brief Imwidget::setNightFlag - public method to change the nightFlag class member
* @param nflag - true for night
*/
void Imwidget::setNightFlag (bool nflag){
nightFlag = nflag ;
update() ;
}
void Imwidget::paintEvent(QPaintEvent *event) {
int w, h ;
if (nightFlag){
qim = qim_0 ;
} else
qim = qim_1 ;
w = this->width() ;
h = this->height() ;
if (!imageLoaded)
return ;
QPainter p (this) ;
p.drawImage (QRect(0,0,1320,700), *qim) ;
if (xloc > 0 && yloc > 0){
p.setPen (Qt::yellow) ;
p.drawRect (xloc-2, yloc-2, 5, 5) ;
}
}
/**
* @brief Imwidget::mousePressEvent - mouse clicks
* @param ev MousePressEvent generated by the click
*
*/
void Imwidget::mousePressEvent (QMouseEvent *ev){
int xy[2];
QToolTip::showText (ev->globalPos(),
QString::number(ev->pos().x())+","+QString::number(ev->pos().y())) ;
xy[0] = ev->pos().x() ;
xy[1] = ev->pos().y() ;
xloc = xy[0] ;
yloc = xy[1] ;
setXY (xloc, yloc);
this->clickedXY(xy);
//repaint() ;
}