811b81ca4f95ea7cecb856c2d78ac9003c6dc160
[android/external-libkmsxx.git] / libkmstest / colorbar.cpp
1 #include <cstdint>
2 #include <drm_fourcc.h>
4 #include <kms++.h>
6 #include "test.h"
8 namespace kms
9 {
10 static const RGB colors32[] = {
11         RGB(255, 255, 255),
12         RGB(255, 0, 0),
13         RGB(255, 255, 255),
14         RGB(0, 255, 0),
15         RGB(255, 255, 255),
16         RGB(0, 0, 255),
17         RGB(255, 255, 255),
18         RGB(200, 200, 200),
19         RGB(255, 255, 255),
20         RGB(100, 100, 100),
21         RGB(255, 255, 255),
22         RGB(50, 50, 50),
23 };
25 static const uint16_t colors16[] = {
26         colors32[0].rgb565(),
27         colors32[1].rgb565(),
28         colors32[2].rgb565(),
29         colors32[3].rgb565(),
30         colors32[4].rgb565(),
31         colors32[5].rgb565(),
32         colors32[6].rgb565(),
33         colors32[7].rgb565(),
34         colors32[8].rgb565(),
35         colors32[9].rgb565(),
36         colors32[10].rgb565(),
37         colors32[11].rgb565(),
38 };
40 static void drm_draw_color_bar_rgb888(DumbFramebuffer& buf, int old_xpos, int xpos, int width)
41 {
42         for (unsigned y = 0; y < buf.height(); ++y) {
43                 RGB bcol = colors32[y * ARRAY_SIZE(colors32) / buf.height()];
44                 uint32_t *line = (uint32_t*)(buf.map(0) + buf.stride(0) * y);
46                 if (old_xpos >= 0) {
47                         for (int x = old_xpos; x < old_xpos + width; ++x)
48                                 line[x] = 0;
49                 }
51                 for (int x = xpos; x < xpos + width; ++x)
52                         line[x] = bcol.argb8888();
53         }
54 }
56 static void drm_draw_color_bar_rgb565(DumbFramebuffer& buf, int old_xpos, int xpos, int width)
57 {
58         static_assert(ARRAY_SIZE(colors32) == ARRAY_SIZE(colors16), "bad colors arrays");
60         for (unsigned y = 0; y < buf.height(); ++y) {
61                 uint16_t bcol = colors16[y * ARRAY_SIZE(colors16) / buf.height()];
62                 uint16_t *line = (uint16_t*)(buf.map(0) + buf.stride(0) * y);
64                 if (old_xpos >= 0) {
65                         for (int x = old_xpos; x < old_xpos + width; ++x)
66                                 line[x] = 0;
67                 }
69                 for (int x = xpos; x < xpos + width; ++x)
70                         line[x] = bcol;
71         }
72 }
74 static void drm_draw_color_bar_semiplanar_yuv(DumbFramebuffer& buf, int old_xpos, int xpos, int width)
75 {
76         const uint8_t colors[] = {
77                 0xff,
78                 0x00,
79                 0xff,
80                 0x20,
81                 0xff,
82                 0x40,
83                 0xff,
84                 0x80,
85                 0xff,
86         };
88         for (unsigned y = 0; y < buf.height(); ++y) {
89                 unsigned int bcol = colors[y * ARRAY_SIZE(colors) / buf.height()];
90                 uint8_t *line = (uint8_t*)(buf.map(0) + buf.stride(0) * y);
92                 if (old_xpos >= 0) {
93                         for (int x = old_xpos; x < old_xpos + width; ++x)
94                                 line[x] = 0;
95                 }
97                 for (int x = xpos; x < xpos + width; ++x)
98                         line[x] = bcol;
99         }
102 void draw_color_bar(DumbFramebuffer& buf, int old_xpos, int xpos, int width)
104         switch (buf.format()) {
105         case PixelFormat::NV12:
106         case PixelFormat::NV21:
107                 // XXX not right but gets something on the screen
108                 drm_draw_color_bar_semiplanar_yuv(buf, old_xpos, xpos, width);
109                 break;
111         case PixelFormat::YUYV:
112         case PixelFormat::UYVY:
113                 // XXX not right but gets something on the screen
114                 drm_draw_color_bar_rgb565(buf, old_xpos, xpos, width);
115                 break;
117         case PixelFormat::RGB565:
118                 drm_draw_color_bar_rgb565(buf, old_xpos, xpos, width);
119                 break;
121         case PixelFormat::XRGB8888:
122                 drm_draw_color_bar_rgb888(buf, old_xpos, xpos, width);
123                 break;
125         default:
126                 ASSERT(false);
127         }