-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmwarray_qimage_convert.cpp
More file actions
123 lines (117 loc) · 3.2 KB
/
Copy pathmwarray_qimage_convert.cpp
File metadata and controls
123 lines (117 loc) · 3.2 KB
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
#include "mwarray_qimage_convert.h"
#include <QDebug>
QImage mwArray2QImage(const mwArray input)
{
mwArray mw_array_size = input.GetDimensions();
int c = input.NumberOfDimensions();
int row = mw_array_size(1);
int col = mw_array_size(2);
if(c == 2)
{
int h = row;
int w = col;
QImage Q_img(w,h,QImage::Format_Indexed8);
// set color count
Q_img.setColorCount(256);
for(int i = 0; i < 256; i++)
{
Q_img.setColor(i, qRgb(i, i, i));
}
for(int i=0;i<h;i++)
{
for(int j=0;j<w;j++)
{
// int a = input.Get(2,i+1,j+1);
// qDebug() << a;
*(Q_img.scanLine(i)+j) = input.Get(2,i+1,j+1);
// qDebug() << *(Q_img.scanLine(i)+j);
}
}
return Q_img;
}
else if(c == 3)
{
int h = row;
int w = col;
QImage Q_img(w,h,QImage::Format_RGB888);
for(int i=0;i<h;i++)
{
for(int j=0;j<w;j++)
{
//
*(Q_img.scanLine(i)+(j*3)) = input.Get(3,i+1,j+1,3);
*(Q_img.scanLine(i)+(j*3)+1) = input.Get(3,i+1,j+1,2);
*(Q_img.scanLine(i)+(j*3)+2) = input.Get(3,i+1,j+1,1);
}
}
return Q_img;
}
}
mwArray QImage2mwArray(QImage input)
{
int h, w;
h = input.height();
w = input.width();
// qDebug() << input.format();
switch(input.format())
{
// 4 channel L to H: BGRA remove A
case QImage::Format_ARGB32:
case QImage::Format_RGB32:
case QImage::Format_ARGB32_Premultiplied:
{
mwSize dims[3] = {h,w,3};
mwArray mw_array(3,dims,mxUINT8_CLASS);
for(int i=0;i<h;i++)
{
for(int j=0;j<w;j++)
{
//RGB
mw_array(i+1,j+1,1) = (UINT8_T)(*(input.scanLine(i)+(j*4)+2));
mw_array(i+1,j+1,2) = (UINT8_T)(*(input.scanLine(i)+(j*4)+1));
mw_array(i+1,j+1,3) = (UINT8_T)(*(input.scanLine(i)+(j*4)));
}
}
return mw_array;
}
// 3 channel
case QImage::Format_RGB888:
{
mwSize dims[3] = {h,w,3};
mwArray mw_array(3,dims,mxUINT8_CLASS);
for(int i=0;i<h;i++)
{
for(int j=0;j<w;j++)
{
//RGB
mw_array(i+1,j+1,1) = (UINT8_T)(*(input.scanLine(i)+(j*3)+2));
mw_array(i+1,j+1,2) = (UINT8_T)(*(input.scanLine(i)+(j*3)+1));
mw_array(i+1,j+1,3) = (UINT8_T)(*(input.scanLine(i)+(j*3)));
}
}
return mw_array;
}
// 1 channel
case QImage::Format_Indexed8:
{
mwArray mw_array(h,w,mxUINT8_CLASS);
for(int i=0;i<h;i++)
{
for(int j=0;j<w;j++)
{
mw_array(i+1,j+1) = (UINT8_T)(*(input.scanLine(i)+j));
// qDebug() << *(input.scanLine(i)+j);
}
}
// test
// int a;
// for (int i=1;i<3;i++)
// {
// // ?,row,col
// a = mw_array.Get(2,1,i);
// qDebug() << a;
// }
return mw_array;
}
}
}