aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'kms++util/src/colorbar.cpp')
-rw-r--r--kms++util/src/colorbar.cpp132
1 files changed, 132 insertions, 0 deletions
diff --git a/kms++util/src/colorbar.cpp b/kms++util/src/colorbar.cpp
new file mode 100644
index 0000000..c08ed9d
--- /dev/null
+++ b/kms++util/src/colorbar.cpp
@@ -0,0 +1,132 @@
1#include <cstdint>
2
3#include <kms++/kms++.h>
4#include <kms++util/kms++util.h>
5
6namespace kms
7{
8static const RGB colors32[] = {
9 RGB(255, 255, 255),
10 RGB(255, 0, 0),
11 RGB(255, 255, 255),
12 RGB(0, 255, 0),
13 RGB(255, 255, 255),
14 RGB(0, 0, 255),
15 RGB(255, 255, 255),
16 RGB(200, 200, 200),
17 RGB(255, 255, 255),
18 RGB(100, 100, 100),
19 RGB(255, 255, 255),
20 RGB(50, 50, 50),
21};
22
23static const uint16_t colors16[] = {
24 colors32[0].rgb565(),
25 colors32[1].rgb565(),
26 colors32[2].rgb565(),
27 colors32[3].rgb565(),
28 colors32[4].rgb565(),
29 colors32[5].rgb565(),
30 colors32[6].rgb565(),
31 colors32[7].rgb565(),
32 colors32[8].rgb565(),
33 colors32[9].rgb565(),
34 colors32[10].rgb565(),
35 colors32[11].rgb565(),
36};
37
38static void drm_draw_color_bar_rgb888(IFramebuffer& buf, int old_xpos, int xpos, int width)
39{
40 for (unsigned y = 0; y < buf.height(); ++y) {
41 RGB bcol = colors32[y * ARRAY_SIZE(colors32) / buf.height()];
42 uint32_t *line = (uint32_t*)(buf.map(0) + buf.stride(0) * y);
43
44 if (old_xpos >= 0) {
45 for (int x = old_xpos; x < old_xpos + width; ++x)
46 line[x] = 0;
47 }
48
49 for (int x = xpos; x < xpos + width; ++x)
50 line[x] = bcol.argb8888();
51 }
52}
53
54static void drm_draw_color_bar_rgb565(IFramebuffer& buf, int old_xpos, int xpos, int width)
55{
56 static_assert(ARRAY_SIZE(colors32) == ARRAY_SIZE(colors16), "bad colors arrays");
57
58 for (unsigned y = 0; y < buf.height(); ++y) {
59 uint16_t bcol = colors16[y * ARRAY_SIZE(colors16) / buf.height()];
60 uint16_t *line = (uint16_t*)(buf.map(0) + buf.stride(0) * y);
61
62 if (old_xpos >= 0) {
63 for (int x = old_xpos; x < old_xpos + width; ++x)
64 line[x] = 0;
65 }
66
67 for (int x = xpos; x < xpos + width; ++x)
68 line[x] = bcol;
69 }
70}
71
72static void drm_draw_color_bar_semiplanar_yuv(IFramebuffer& buf, int old_xpos, int xpos, int width)
73{
74 const uint8_t colors[] = {
75 0xff,
76 0x00,
77 0xff,
78 0x20,
79 0xff,
80 0x40,
81 0xff,
82 0x80,
83 0xff,
84 };
85
86 for (unsigned y = 0; y < buf.height(); ++y) {
87 unsigned int bcol = colors[y * ARRAY_SIZE(colors) / buf.height()];
88 uint8_t *line = (uint8_t*)(buf.map(0) + buf.stride(0) * y);
89
90 if (old_xpos >= 0) {
91 for (int x = old_xpos; x < old_xpos + width; ++x)
92 line[x] = 0;
93 }
94
95 for (int x = xpos; x < xpos + width; ++x)
96 line[x] = bcol;
97 }
98}
99
100void draw_color_bar(IFramebuffer& buf, int old_xpos, int xpos, int width)
101{
102 switch (buf.format()) {
103 case PixelFormat::NV12:
104 case PixelFormat::NV21:
105 // XXX not right but gets something on the screen
106 drm_draw_color_bar_semiplanar_yuv(buf, old_xpos, xpos, width);
107 break;
108
109 case PixelFormat::YUYV:
110 case PixelFormat::UYVY:
111 // XXX not right but gets something on the screen
112 drm_draw_color_bar_rgb565(buf, old_xpos, xpos, width);
113 break;
114
115 case PixelFormat::RGB565:
116 drm_draw_color_bar_rgb565(buf, old_xpos, xpos, width);
117 break;
118
119 case PixelFormat::BGR565:
120 // XXX not right, red and blue are reversed
121 drm_draw_color_bar_rgb565(buf, old_xpos, xpos, width);
122 break;
123
124 case PixelFormat::XRGB8888:
125 drm_draw_color_bar_rgb888(buf, old_xpos, xpos, width);
126 break;
127
128 default:
129 ASSERT(false);
130 }
131}
132}