libkmstest: move color bar code to libkmstest
authorTomi Valkeinen <tomi.valkeinen@iki.fi>
Fri, 2 Oct 2015 19:03:51 +0000 (22:03 +0300)
committerTomi Valkeinen <tomi.valkeinen@iki.fi>
Sat, 3 Oct 2015 13:59:19 +0000 (16:59 +0300)
libkmstest/colorbar.cpp [new file with mode: 0644]
libkmstest/colorbar.h [new file with mode: 0644]
libkmstest/test.h
tests/db.cpp

diff --git a/libkmstest/colorbar.cpp b/libkmstest/colorbar.cpp
new file mode 100644 (file)
index 0000000..bc9cdca
--- /dev/null
@@ -0,0 +1,129 @@
+#include <cstdint>
+#include <drm_fourcc.h>
+
+#include <kms++.h>
+
+#include "test.h"
+
+namespace kms
+{
+static const RGB colors32[] = {
+       RGB(255, 255, 255),
+       RGB(255, 0, 0),
+       RGB(255, 255, 255),
+       RGB(0, 255, 0),
+       RGB(255, 255, 255),
+       RGB(0, 0, 255),
+       RGB(255, 255, 255),
+       RGB(200, 200, 200),
+       RGB(255, 255, 255),
+       RGB(100, 100, 100),
+       RGB(255, 255, 255),
+       RGB(50, 50, 50),
+};
+
+static const uint16_t colors16[] = {
+       colors32[0].rgb565(),
+       colors32[1].rgb565(),
+       colors32[2].rgb565(),
+       colors32[3].rgb565(),
+       colors32[4].rgb565(),
+       colors32[5].rgb565(),
+       colors32[6].rgb565(),
+       colors32[7].rgb565(),
+       colors32[8].rgb565(),
+       colors32[9].rgb565(),
+       colors32[10].rgb565(),
+       colors32[11].rgb565(),
+};
+
+static void drm_draw_color_bar_rgb888(DumbFramebuffer& buf, int old_xpos, int xpos, int width)
+{
+       for (unsigned y = 0; y < buf.height(); ++y) {
+               RGB bcol = colors32[y * ARRAY_SIZE(colors32) / buf.height()];
+               uint32_t *line = (uint32_t*)(buf.map(0) + buf.stride(0) * y);
+
+               if (old_xpos >= 0) {
+                       for (int x = old_xpos; x < old_xpos + width; ++x)
+                               line[x] = 0;
+               }
+
+               for (int x = xpos; x < xpos + width; ++x)
+                       line[x] = bcol.raw;
+       }
+}
+
+static void drm_draw_color_bar_rgb565(DumbFramebuffer& buf, int old_xpos, int xpos, int width)
+{
+       static_assert(ARRAY_SIZE(colors32) == ARRAY_SIZE(colors16), "bad colors arrays");
+
+       for (unsigned y = 0; y < buf.height(); ++y) {
+               uint16_t bcol = colors16[y * ARRAY_SIZE(colors16) / buf.height()];
+               uint16_t *line = (uint16_t*)(buf.map(0) + buf.stride(0) * y);
+
+               if (old_xpos >= 0) {
+                       for (int x = old_xpos; x < old_xpos + width; ++x)
+                               line[x] = 0;
+               }
+
+               for (int x = xpos; x < xpos + width; ++x)
+                       line[x] = bcol;
+       }
+}
+
+static void drm_draw_color_bar_semiplanar_yuv(DumbFramebuffer& buf, int old_xpos, int xpos, int width)
+{
+       const uint8_t colors[] = {
+               0xff,
+               0x00,
+               0xff,
+               0x20,
+               0xff,
+               0x40,
+               0xff,
+               0x80,
+               0xff,
+       };
+
+       for (unsigned y = 0; y < buf.height(); ++y) {
+               unsigned int bcol = colors[y * ARRAY_SIZE(colors) / buf.height()];
+               uint8_t *line = (uint8_t*)(buf.map(0) + buf.stride(0) * y);
+
+               if (old_xpos >= 0) {
+                       for (int x = old_xpos; x < old_xpos + width; ++x)
+                               line[x] = 0;
+               }
+
+               for (int x = xpos; x < xpos + width; ++x)
+                       line[x] = bcol;
+       }
+}
+
+void draw_color_bar(DumbFramebuffer& buf, int old_xpos, int xpos, int width)
+{
+       switch (buf.format()) {
+       case DRM_FORMAT_NV12:
+       case DRM_FORMAT_NV21:
+               // XXX not right but gets something on the screen
+               drm_draw_color_bar_semiplanar_yuv(buf, old_xpos, xpos, width);
+               break;
+
+       case DRM_FORMAT_YUYV:
+       case DRM_FORMAT_UYVY:
+               // XXX not right but gets something on the screen
+               drm_draw_color_bar_rgb565(buf, old_xpos, xpos, width);
+               break;
+
+       case DRM_FORMAT_RGB565:
+               drm_draw_color_bar_rgb565(buf, old_xpos, xpos, width);
+               break;
+
+       case DRM_FORMAT_XRGB8888:
+               drm_draw_color_bar_rgb888(buf, old_xpos, xpos, width);
+               break;
+
+       default:
+               ASSERT(false);
+       }
+}
+}
diff --git a/libkmstest/colorbar.h b/libkmstest/colorbar.h
new file mode 100644 (file)
index 0000000..a47d64d
--- /dev/null
@@ -0,0 +1,6 @@
+#pragma once
+
+namespace kms
+{
+void draw_color_bar(kms::DumbFramebuffer& buf, int old_xpos, int xpos, int width);
+}
index f4cec599e7e83cc9d6c127f04650466e4d1d9594..fbc4727d3d1e396848519b9d1e2a6f324f690a6e 100644 (file)
@@ -3,6 +3,7 @@
 #include "color.h"
 #include "conv.h"
 #include "testpat.h"
+#include "colorbar.h"
 
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 
index 47ed273137b5ca3bbfca0dfc61a42f20805620ee..12db4346a18e548a2175abc4f3cc0af72b065b13 100644 (file)
@@ -12,8 +12,6 @@
 using namespace std;
 using namespace kms;
 
-static void draw_color_bar(DumbFramebuffer& buf, int old_xpos, int xpos, int width);
-
 static void main_loop(Card& card);
 
 class OutputFlipHandler
@@ -175,124 +173,3 @@ static void main_loop(Card& card)
                }
        }
 }
-
-
-static const RGB colors32[] = {
-       RGB(255, 255, 255),
-       RGB(255, 0, 0),
-       RGB(255, 255, 255),
-       RGB(0, 255, 0),
-       RGB(255, 255, 255),
-       RGB(0, 0, 255),
-       RGB(255, 255, 255),
-       RGB(200, 200, 200),
-       RGB(255, 255, 255),
-       RGB(100, 100, 100),
-       RGB(255, 255, 255),
-       RGB(50, 50, 50),
-};
-
-static const uint16_t colors16[] = {
-       colors32[0].rgb565(),
-       colors32[1].rgb565(),
-       colors32[2].rgb565(),
-       colors32[3].rgb565(),
-       colors32[4].rgb565(),
-       colors32[5].rgb565(),
-       colors32[6].rgb565(),
-       colors32[7].rgb565(),
-       colors32[8].rgb565(),
-       colors32[9].rgb565(),
-       colors32[10].rgb565(),
-       colors32[11].rgb565(),
-};
-
-static void drm_draw_color_bar_rgb888(DumbFramebuffer& buf, int old_xpos, int xpos, int width)
-{
-       for (unsigned y = 0; y < buf.height(); ++y) {
-               RGB bcol = colors32[y * ARRAY_SIZE(colors32) / buf.height()];
-               uint32_t *line = (uint32_t*)(buf.map(0) + buf.stride(0) * y);
-
-               if (old_xpos >= 0) {
-                       for (int x = old_xpos; x < old_xpos + width; ++x)
-                               line[x] = 0;
-               }
-
-               for (int x = xpos; x < xpos + width; ++x)
-                       line[x] = bcol.raw;
-       }
-}
-
-static void drm_draw_color_bar_rgb565(DumbFramebuffer& buf, int old_xpos, int xpos, int width)
-{
-       static_assert(ARRAY_SIZE(colors32) == ARRAY_SIZE(colors16), "bad colors arrays");
-
-       for (unsigned y = 0; y < buf.height(); ++y) {
-               uint16_t bcol = colors16[y * ARRAY_SIZE(colors16) / buf.height()];
-               uint16_t *line = (uint16_t*)(buf.map(0) + buf.stride(0) * y);
-
-               if (old_xpos >= 0) {
-                       for (int x = old_xpos; x < old_xpos + width; ++x)
-                               line[x] = 0;
-               }
-
-               for (int x = xpos; x < xpos + width; ++x)
-                       line[x] = bcol;
-       }
-}
-
-static void drm_draw_color_bar_semiplanar_yuv(DumbFramebuffer& buf, int old_xpos, int xpos, int width)
-{
-       const uint8_t colors[] = {
-               0xff,
-               0x00,
-               0xff,
-               0x20,
-               0xff,
-               0x40,
-               0xff,
-               0x80,
-               0xff,
-       };
-
-       for (unsigned y = 0; y < buf.height(); ++y) {
-               unsigned int bcol = colors[y * ARRAY_SIZE(colors) / buf.height()];
-               uint8_t *line = (uint8_t*)(buf.map(0) + buf.stride(0) * y);
-
-               if (old_xpos >= 0) {
-                       for (int x = old_xpos; x < old_xpos + width; ++x)
-                               line[x] = 0;
-               }
-
-               for (int x = xpos; x < xpos + width; ++x)
-                       line[x] = bcol;
-       }
-}
-
-static void draw_color_bar(DumbFramebuffer& buf, int old_xpos, int xpos, int width)
-{
-       switch (buf.format()) {
-       case DRM_FORMAT_NV12:
-       case DRM_FORMAT_NV21:
-               // XXX not right but gets something on the screen
-               drm_draw_color_bar_semiplanar_yuv(buf, old_xpos, xpos, width);
-               break;
-
-       case DRM_FORMAT_YUYV:
-       case DRM_FORMAT_UYVY:
-               // XXX not right but gets something on the screen
-               drm_draw_color_bar_rgb565(buf, old_xpos, xpos, width);
-               break;
-
-       case DRM_FORMAT_RGB565:
-               drm_draw_color_bar_rgb565(buf, old_xpos, xpos, width);
-               break;
-
-       case DRM_FORMAT_XRGB8888:
-               drm_draw_color_bar_rgb888(buf, old_xpos, xpos, width);
-               break;
-
-       default:
-               ASSERT(false);
-       }
-}