bca8dc6c57a3a0b71eab90f378382e0b0d4b000b
1 #include <cstdint>
3 #include <kms++/kms++.h>
4 #include <kms++util/kms++util.h>
6 namespace kms
7 {
8 static 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 };
23 static 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 };
38 static void drm_draw_color_bar_rgb888(IMappedFramebuffer& 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);
44 if (old_xpos >= 0) {
45 for (int x = old_xpos; x < old_xpos + width; ++x)
46 line[x] = 0;
47 }
49 for (int x = xpos; x < xpos + width; ++x)
50 line[x] = bcol.argb8888();
51 }
52 }
54 static void drm_draw_color_bar_rgb565(IMappedFramebuffer& buf, int old_xpos, int xpos, int width)
55 {
56 static_assert(ARRAY_SIZE(colors32) == ARRAY_SIZE(colors16), "bad colors arrays");
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);
62 if (old_xpos >= 0) {
63 for (int x = old_xpos; x < old_xpos + width; ++x)
64 line[x] = 0;
65 }
67 for (int x = xpos; x < xpos + width; ++x)
68 line[x] = bcol;
69 }
70 }
72 static void drm_draw_color_bar_semiplanar_yuv(IMappedFramebuffer& 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 };
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);
90 if (old_xpos >= 0) {
91 for (int x = old_xpos; x < old_xpos + width; ++x)
92 line[x] = 0;
93 }
95 for (int x = xpos; x < xpos + width; ++x)
96 line[x] = bcol;
97 }
98 }
100 void draw_color_bar(IMappedFramebuffer& 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;
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;
115 case PixelFormat::RGB565:
116 drm_draw_color_bar_rgb565(buf, old_xpos, xpos, width);
117 break;
119 case PixelFormat::XRGB8888:
120 drm_draw_color_bar_rgb888(buf, old_xpos, xpos, width);
121 break;
123 default:
124 ASSERT(false);
125 }
126 }
127 }