-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipl2qimg.h
46 lines (42 loc) · 807 Bytes
/
ipl2qimg.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
#ifndef IPL2QIMG_H
#define IPL2QIMG_H
#endif // IPL2QIMG_H
void IplImage22QImage(IplImage* iplImg,QImage *qimg)
{
int h = iplImg->height;
int w = iplImg->width;
int channels = iplImg->nChannels;
QImage *qimg1 = new QImage(w, h, QImage::Format_ARGB32);
char *data = iplImg->imageData;
for (int y = 0; y < h; y++, data += iplImg->widthStep)
{
for (int x = 0; x < w; x++)
{
char r, g, b, a = 0;
if (channels == 1)
{
r = data[x * channels];
g = data[x * channels];
b = data[x * channels];
}
else if (channels == 3 || channels == 4)
{
r = data[x * channels + 2];
g = data[x * channels + 1];
b = data[x * channels];
}
if (channels == 4)
{
a = data[x * channels + 3];
qimg1->setPixel(x, y, qRgba(r, g, b, a));
}
else
{
qimg1->setPixel(x, y, qRgb(r, g, b));
}
}
}
//return qimg;
*qimg=*qimg1;
delete(qimg1);
}