This repository has been archived by the owner on Sep 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
qdisplay.cpp
196 lines (178 loc) · 4.14 KB
/
qdisplay.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/* Copyright (c) 2015, Niklas Hauser
* All Rights Reserved.
*
* The file is part of the upainter library and is released under the GPLv3
* license. See the file `LICENSE` for the full license governing this code.
* ------------------------------------------------------------------------ */
#include "qdisplay.hpp"
#include <ges/pixel_color.hpp>
#include <QDebug>
namespace modm
{
namespace ges
{
inline QImage::Format
toQImageFormat(PixelFormat format)
{
switch(format)
{
case PixelFormat::L1:
return QImage::Format_MonoLSB;
case PixelFormat::L8:
return QImage::Format_Grayscale8;
case PixelFormat::ARGB2:
case PixelFormat::RGB332:
case PixelFormat::ARGB1:
case PixelFormat::RGB1:
case PixelFormat::AL1:
case PixelFormat::L2:
case PixelFormat::AL2:
case PixelFormat::L4:
case PixelFormat::AL4:
return QImage::Format_Indexed8;
case PixelFormat::AL8:
case PixelFormat::ARGB4:
return QImage::Format_ARGB4444_Premultiplied;
case PixelFormat::ARGB1555:
return QImage::Format_RGB555;
case PixelFormat::RGB565:
return QImage::Format_RGB16;
case PixelFormat::RGB8:
return QImage::Format_RGBX8888;
// return QImage::Format_RGB888;
case PixelFormat::ARGB8:
return QImage::Format_RGBA8888_Premultiplied;
default:
return QImage::Format_Invalid;
}
}
QDisplay::QDisplay(uchar *data, const uint16_t width, const uint16_t height, const PixelFormat format, QWidget *parent) :
QWidget(parent), image(data, width, height, toQImageFormat(format))
{
// manually create color tables and attach to image if necessary
if (format == PixelFormat::L1)
{
QVector<QRgb> table{qRgb(0,0,0), qRgb(0xff, 0xff, 0xff)};
image.setColorTable(table);
}
else if (format == PixelFormat::AL1)
{
QVector<QRgb> table
{
Color(ColorAL1(0b00)).getValue(),
Color(ColorAL1(0b01)).getValue(),
Color(ColorAL1(0b10)).getValue(),
Color(ColorAL1(0b11)).getValue(),
};
image.setColorTable(table);
}
else if (format == PixelFormat::L2)
{
QVector<QRgb> table
{
Color(ColorL2(0b00)).getValue(),
Color(ColorL2(0b01)).getValue(),
Color(ColorL2(0b10)).getValue(),
Color(ColorL2(0b11)).getValue(),
};
image.setColorTable(table);
}
else if (format == PixelFormat::AL2)
{
QVector<QRgb> table(16);
for(uint8_t i = 0; i < 16; i++)
{
Color c = Color(ColorAL2(i));
table[i] = c.getValue();
}
image.setColorTable(table);
}
else if (format == PixelFormat::L4)
{
QVector<QRgb> table(16);
for(uint8_t i = 0; i < 16; i++)
{
Color c = Color(ColorL4(i));
table[i] = c.getValue();
}
image.setColorTable(table);
}
else if (format == PixelFormat::AL4)
{
QVector<QRgb> table(256);
for(int i = 0; i < 256; i++)
{
Color c = Color(ColorAL4(uint8_t(i)));
table[i] = c.getValue();
}
image.setColorTable(table);
}
else if (format == PixelFormat::RGB1)
{
QVector<QRgb> table
{
qRgb(0, 0, 0),
qRgb(0, 0, 0xff),
qRgb(0, 0xff, 0),
qRgb(0, 0xff, 0xff),
qRgb(0xff, 0, 0),
qRgb(0xff, 0, 0xff),
qRgb(0xff, 0xff, 0),
qRgb(0xff, 0xff, 0xff)
};
image.setColorTable(table);
}
else if (format == PixelFormat::ARGB1)
{
QVector<QRgb> table
{
qRgba(0, 0, 0, 0),
qRgba(0, 0, 0xff, 0),
qRgba(0, 0xff, 0, 0),
qRgba(0, 0xff, 0xff, 0),
qRgba(0xff, 0, 0, 0),
qRgba(0xff, 0, 0xff, 0),
qRgba(0xff, 0xff, 0, 0),
qRgba(0xff, 0xff, 0xff, 0),
qRgb(0, 0, 0),
qRgb(0, 0, 0xff),
qRgb(0, 0xff, 0),
qRgb(0, 0xff, 0xff),
qRgb(0xff, 0, 0),
qRgb(0xff, 0, 0xff),
qRgb(0xff, 0xff, 0),
qRgb(0xff, 0xff, 0xff)
};
image.setColorTable(table);
}
else if (format == PixelFormat::RGB332)
{
QVector<QRgb> table(256);
for(int i = 0; i < 256; i++)
{
Color c = Color(ColorRGB332(uint8_t(i)));
table[i] = c.getValue();
}
image.setColorTable(table);
}
else if (format == PixelFormat::ARGB2)
{
QVector<QRgb> table(256);
for(int i = 0; i < 256; i++)
{
Color c = Color(ColorARGB2(uint8_t(i)));
table[i] = c.getValue();
}
image.setColorTable(table);
}
}
void
QDisplay::paintEvent(QPaintEvent */*event*/)
{
QPainter painter(this);
painter.scale(10, 10);
painter.drawImage(0, 0, image);
painter.end();
}
} // namespace ges
} // namespace modm