1 #include <cstdint>
3 #include <kms++.h>
5 #include "test.h"
7 namespace kms
8 {
9 static const RGB colors32[] = {
10 RGB(255, 255, 255),
11 RGB(255, 0, 0),
12 RGB(255, 255, 255),
13 RGB(0, 255, 0),
14 RGB(255, 255, 255),
15 RGB(0, 0, 255),
16 RGB(255, 255, 255),
17 RGB(200, 200, 200),
18 RGB(255, 255, 255),
19 RGB(100, 100, 100),
20 RGB(255, 255, 255),
21 RGB(50, 50, 50),
22 };
24 static const uint16_t colors16[] = {
25 colors32[0].rgb565(),
26 colors32[1].rgb565(),
27 colors32[2].rgb565(),
28 colors32[3].rgb565(),
29 colors32[4].rgb565(),
30 colors32[5].rgb565(),
31 colors32[6].rgb565(),
32 colors32[7].rgb565(),
33 colors32[8].rgb565(),
34 colors32[9].rgb565(),
35 colors32[10].rgb565(),
36 colors32[11].rgb565(),
37 };
39 static void drm_draw_color_bar_rgb888(IMappedFramebuffer& buf, int old_xpos, int xpos, int width)
40 {
41 for (unsigned y = 0; y < buf.height(); ++y) {
42 RGB bcol = colors32[y * ARRAY_SIZE(colors32) / buf.height()];
43 uint32_t *line = (uint32_t*)(buf.map(0) + buf.stride(0) * y);
45 if (old_xpos >= 0) {
46 for (int x = old_xpos; x < old_xpos + width; ++x)
47 line[x] = 0;
48 }
50 for (int x = xpos; x < xpos + width; ++x)
51 line[x] = bcol.argb8888();
52 }
53 }
55 static void drm_draw_color_bar_rgb565(IMappedFramebuffer& buf, int old_xpos, int xpos, int width)
56 {
57 static_assert(ARRAY_SIZE(colors32) == ARRAY_SIZE(colors16), "bad colors arrays");
59 for (unsigned y = 0; y < buf.height(); ++y) {
60 uint16_t bcol = colors16[y * ARRAY_SIZE(colors16) / buf.height()];
61 uint16_t *line = (uint16_t*)(buf.map(0) + buf.stride(0) * y);
63 if (old_xpos >= 0) {
64 for (int x = old_xpos; x < old_xpos + width; ++x)
65 line[x] = 0;
66 }
68 for (int x = xpos; x < xpos + width; ++x)
69 line[x] = bcol;
70 }
71 }
73 static void drm_draw_color_bar_semiplanar_yuv(IMappedFramebuffer& buf, int old_xpos, int xpos, int width)
74 {
75 const uint8_t colors[] = {
76 0xff,
77 0x00,
78 0xff,
79 0x20,
80 0xff,
81 0x40,
82 0xff,
83 0x80,
84 0xff,
85 };
87 for (unsigned y = 0; y < buf.height(); ++y) {
88 unsigned int bcol = colors[y * ARRAY_SIZE(colors) / buf.height()];
89 uint8_t *line = (uint8_t*)(buf.map(0) + buf.stride(0) * y);
91 if (old_xpos >= 0) {
92 for (int x = old_xpos; x < old_xpos + width; ++x)
93 line[x] = 0;
94 }
96 for (int x = xpos; x < xpos + width; ++x)
97 line[x] = bcol;
98 }
99 }
101 void draw_color_bar(IMappedFramebuffer& buf, int old_xpos, int xpos, int width)
102 {
103 switch (buf.format()) {
104 case PixelFormat::NV12:
105 case PixelFormat::NV21:
106 // XXX not right but gets something on the screen
107 drm_draw_color_bar_semiplanar_yuv(buf, old_xpos, xpos, width);
108 break;
110 case PixelFormat::YUYV:
111 case PixelFormat::UYVY:
112 // XXX not right but gets something on the screen
113 drm_draw_color_bar_rgb565(buf, old_xpos, xpos, width);
114 break;
116 case PixelFormat::RGB565:
117 drm_draw_color_bar_rgb565(buf, old_xpos, xpos, width);
118 break;
120 case PixelFormat::XRGB8888:
121 drm_draw_color_bar_rgb888(buf, old_xpos, xpos, width);
122 break;
124 default:
125 ASSERT(false);
126 }
127 }
128 }