From a5c28bcb2ead34e921617711ebf94ffcb5d72878 Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Mon, 23 May 2016 09:54:08 +0300 Subject: File/dir renames --- CMakeLists.txt | 4 +- kmscube/CMakeLists.txt | 2 +- libkms++util/CMakeLists.txt | 5 + libkms++util/color.cpp | 93 ++++++ libkms++util/color.h | 39 +++ libkms++util/colorbar.cpp | 128 ++++++++ libkms++util/cpuframebuffer.cpp | 36 +++ libkms++util/cpuframebuffer.h | 44 +++ libkms++util/extcpuframebuffer.cpp | 50 +++ libkms++util/extcpuframebuffer.h | 42 +++ libkms++util/kmstest.h | 15 + libkms++util/opts.cpp | 117 +++++++ libkms++util/opts.h | 38 +++ libkms++util/test.h | 32 ++ libkms++util/testpat.cpp | 291 ++++++++++++++++++ libkmstest/CMakeLists.txt | 5 - libkmstest/color.cpp | 93 ------ libkmstest/color.h | 39 --- libkmstest/colorbar.cpp | 128 -------- libkmstest/cpuframebuffer.cpp | 36 --- libkmstest/cpuframebuffer.h | 44 --- libkmstest/extcpuframebuffer.cpp | 50 --- libkmstest/extcpuframebuffer.h | 42 --- libkmstest/kmstest.h | 15 - libkmstest/opts.cpp | 117 ------- libkmstest/opts.h | 38 --- libkmstest/test.h | 32 -- libkmstest/testpat.cpp | 291 ------------------ py/CMakeLists.txt | 4 +- py/pykmstest.cpp | 31 -- py/pykmsutil.cpp | 31 ++ tests/CMakeLists.txt | 20 -- tests/db.cpp | 265 ---------------- tests/fbtestpat.cpp | 60 ---- tests/kmscapture.cpp | 435 -------------------------- tests/kmsprint.cpp | 221 -------------- tests/kmsview.cpp | 92 ------ tests/testpat.cpp | 604 ------------------------------------- utils/CMakeLists.txt | 20 ++ utils/db.cpp | 265 ++++++++++++++++ utils/fbtestpat.cpp | 60 ++++ utils/kmscapture.cpp | 435 ++++++++++++++++++++++++++ utils/kmsprint.cpp | 221 ++++++++++++++ utils/kmsview.cpp | 92 ++++++ utils/testpat.cpp | 604 +++++++++++++++++++++++++++++++++++++ 45 files changed, 2663 insertions(+), 2663 deletions(-) create mode 100644 libkms++util/CMakeLists.txt create mode 100644 libkms++util/color.cpp create mode 100644 libkms++util/color.h create mode 100644 libkms++util/colorbar.cpp create mode 100644 libkms++util/cpuframebuffer.cpp create mode 100644 libkms++util/cpuframebuffer.h create mode 100644 libkms++util/extcpuframebuffer.cpp create mode 100644 libkms++util/extcpuframebuffer.h create mode 100644 libkms++util/kmstest.h create mode 100644 libkms++util/opts.cpp create mode 100644 libkms++util/opts.h create mode 100644 libkms++util/test.h create mode 100644 libkms++util/testpat.cpp delete mode 100644 libkmstest/CMakeLists.txt delete mode 100644 libkmstest/color.cpp delete mode 100644 libkmstest/color.h delete mode 100644 libkmstest/colorbar.cpp delete mode 100644 libkmstest/cpuframebuffer.cpp delete mode 100644 libkmstest/cpuframebuffer.h delete mode 100644 libkmstest/extcpuframebuffer.cpp delete mode 100644 libkmstest/extcpuframebuffer.h delete mode 100644 libkmstest/kmstest.h delete mode 100644 libkmstest/opts.cpp delete mode 100644 libkmstest/opts.h delete mode 100644 libkmstest/test.h delete mode 100644 libkmstest/testpat.cpp delete mode 100644 py/pykmstest.cpp create mode 100644 py/pykmsutil.cpp delete mode 100644 tests/CMakeLists.txt delete mode 100644 tests/db.cpp delete mode 100644 tests/fbtestpat.cpp delete mode 100644 tests/kmscapture.cpp delete mode 100644 tests/kmsprint.cpp delete mode 100644 tests/kmsview.cpp delete mode 100644 tests/testpat.cpp create mode 100644 utils/CMakeLists.txt create mode 100644 utils/db.cpp create mode 100644 utils/fbtestpat.cpp create mode 100644 utils/kmscapture.cpp create mode 100644 utils/kmsprint.cpp create mode 100644 utils/kmsview.cpp create mode 100644 utils/testpat.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b968102..f1e13c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,8 +38,8 @@ pkg_check_modules(LIBDRM libdrm REQUIRED) enable_testing() add_subdirectory(libkms++) -add_subdirectory(libkmstest) -add_subdirectory(tests) +add_subdirectory(libkms++util) +add_subdirectory(utils) if(LIBKMS_ENABLE_KMSCUBE) add_subdirectory(kmscube) diff --git a/kmscube/CMakeLists.txt b/kmscube/CMakeLists.txt index 15b4dbf..b6bac29 100644 --- a/kmscube/CMakeLists.txt +++ b/kmscube/CMakeLists.txt @@ -32,7 +32,7 @@ link_directories( add_executable (kmscube cube.cpp cube.h cube-egl.cpp cube-egl.h cube-gles2.cpp cube-gles2.h cube-null.cpp cube-gbm.cpp cube-x11.cpp cube-wl.cpp esTransform.c esTransform.h) -target_link_libraries(kmscube kms++ kmstest +target_link_libraries(kmscube kms++ kms++util ${LIBDRM_LIBRARIES} ${GLESv2_LIBRARIES} ${EGL_LIBRARIES} diff --git a/libkms++util/CMakeLists.txt b/libkms++util/CMakeLists.txt new file mode 100644 index 0000000..d08ec84 --- /dev/null +++ b/libkms++util/CMakeLists.txt @@ -0,0 +1,5 @@ +file(GLOB SRCS "*.cpp" "*.h") +add_library(kms++util ${SRCS}) + +target_link_libraries(kms++util kms++) +target_include_directories(kms++util PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/libkms++util/color.cpp b/libkms++util/color.cpp new file mode 100644 index 0000000..490ff64 --- /dev/null +++ b/libkms++util/color.cpp @@ -0,0 +1,93 @@ +#include "color.h" + +namespace kms +{ +RGB::RGB() +{ + r = g = b = 0; + a = 255; +} + +RGB::RGB(uint8_t r, uint8_t g, uint8_t b) + :RGB(255, r, g, b) +{ +} + +RGB::RGB(uint8_t a, uint8_t r, uint8_t g, uint8_t b) +{ + this->r = r; + this->g = g; + this->b = b; + this->a = a; +} + +RGB::RGB(uint32_t argb) +{ + this->b = (argb >> 0) & 0xff; + this->g = (argb >> 8) & 0xff; + this->r = (argb >> 16) & 0xff; + this->a = (argb >> 24) & 0xff; +} + +uint32_t RGB::rgb888() const +{ + return (r << 16) | (g << 8) | (b << 0); +} + +uint32_t RGB::argb8888() const +{ + return (a << 24) | (r << 16) | (g << 8) | (b << 0); +} + +uint32_t RGB::abgr8888() const +{ + return (a << 24) | (b << 16) | (g << 8) | (r << 0); +} + +uint16_t RGB::rgb565() const +{ + return ((r >> 3) << 11) | ((g >> 2) << 5) | ((b >> 3) << 0); +} + +YUV RGB::yuv() const +{ + return YUV(*this); +} + + +YUV::YUV() +{ + y = u = v = a = 0; +} + +YUV::YUV(uint8_t y, uint8_t u, uint8_t v) +{ + this->y = y; + this->u = u; + this->v = v; + this->a = 0; +} + +static inline uint8_t MAKE_YUV_601_Y(uint8_t r, uint8_t g, uint8_t b) +{ + return (((66 * r + 129 * g + 25 * b + 128) >> 8) + 16); +} + +static inline uint8_t MAKE_YUV_601_U(uint8_t r, uint8_t g, uint8_t b) +{ + return (((-38 * r - 74 * g + 112 * b + 128) >> 8) + 128); +} + +static inline uint8_t MAKE_YUV_601_V(uint8_t r, uint8_t g, uint8_t b) +{ + return (((112 * r - 94 * g - 18 * b + 128) >> 8) + 128); +} + +YUV::YUV(const RGB& rgb) +{ + this->y = MAKE_YUV_601_Y(rgb.r, rgb.g, rgb.b); + this->u = MAKE_YUV_601_U(rgb.r, rgb.g, rgb.b); + this->v = MAKE_YUV_601_V(rgb.r, rgb.g, rgb.b); + this->a = rgb.a; +} +} diff --git a/libkms++util/color.h b/libkms++util/color.h new file mode 100644 index 0000000..ef85a67 --- /dev/null +++ b/libkms++util/color.h @@ -0,0 +1,39 @@ +#pragma once + +#include + +namespace kms +{ +struct YUV; + +struct RGB +{ + RGB(); + RGB(uint8_t r, uint8_t g, uint8_t b); + RGB(uint8_t a, uint8_t r, uint8_t g, uint8_t b); + RGB(uint32_t argb); + + uint32_t rgb888() const; + uint32_t argb8888() const; + uint32_t abgr8888() const; + uint16_t rgb565() const; + YUV yuv() const; + + uint8_t b; + uint8_t g; + uint8_t r; + uint8_t a; +}; + +struct YUV +{ + YUV(); + YUV(uint8_t y, uint8_t u, uint8_t v); + YUV(const RGB& rgb); + + uint8_t v; + uint8_t u; + uint8_t y; + uint8_t a; +}; +} diff --git a/libkms++util/colorbar.cpp b/libkms++util/colorbar.cpp new file mode 100644 index 0000000..9fbec28 --- /dev/null +++ b/libkms++util/colorbar.cpp @@ -0,0 +1,128 @@ +#include + +#include + +#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(IMappedFramebuffer& 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.argb8888(); + } +} + +static void drm_draw_color_bar_rgb565(IMappedFramebuffer& 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(IMappedFramebuffer& 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(IMappedFramebuffer& buf, int old_xpos, int xpos, int width) +{ + switch (buf.format()) { + case PixelFormat::NV12: + case PixelFormat::NV21: + // XXX not right but gets something on the screen + drm_draw_color_bar_semiplanar_yuv(buf, old_xpos, xpos, width); + break; + + case PixelFormat::YUYV: + case PixelFormat::UYVY: + // XXX not right but gets something on the screen + drm_draw_color_bar_rgb565(buf, old_xpos, xpos, width); + break; + + case PixelFormat::RGB565: + drm_draw_color_bar_rgb565(buf, old_xpos, xpos, width); + break; + + case PixelFormat::XRGB8888: + drm_draw_color_bar_rgb888(buf, old_xpos, xpos, width); + break; + + default: + ASSERT(false); + } +} +} diff --git a/libkms++util/cpuframebuffer.cpp b/libkms++util/cpuframebuffer.cpp new file mode 100644 index 0000000..1f14ddc --- /dev/null +++ b/libkms++util/cpuframebuffer.cpp @@ -0,0 +1,36 @@ +#include + +#include "cpuframebuffer.h" + +using namespace std; + +namespace kms { + +CPUFramebuffer::CPUFramebuffer(uint32_t width, uint32_t height, PixelFormat format) + : m_width(width), m_height(height), m_format(format) +{ + const PixelFormatInfo& format_info = get_pixel_format_info(m_format); + + m_num_planes = format_info.num_planes; + + for (unsigned i = 0; i < format_info.num_planes; ++i) { + const PixelFormatPlaneInfo& pi = format_info.planes[i]; + FramebufferPlane& plane = m_planes[i]; + + plane.stride = width * pi.bitspp / 8; + plane.size = plane.stride * height/ pi.ysub; + plane.offset = 0; + plane.map = new uint8_t[plane.size]; + } +} + +CPUFramebuffer::~CPUFramebuffer() +{ + for (unsigned i = 0; i < m_num_planes; ++i) { + FramebufferPlane& plane = m_planes[i]; + + delete plane.map; + } +} + +} diff --git a/libkms++util/cpuframebuffer.h b/libkms++util/cpuframebuffer.h new file mode 100644 index 0000000..d2073bc --- /dev/null +++ b/libkms++util/cpuframebuffer.h @@ -0,0 +1,44 @@ +#pragma once + +#include "kms++.h" + +namespace kms +{ + +class CPUFramebuffer : public IMappedFramebuffer { +public: + CPUFramebuffer(uint32_t width, uint32_t height, PixelFormat format); + + virtual ~CPUFramebuffer(); + + CPUFramebuffer(const CPUFramebuffer& other) = delete; + CPUFramebuffer& operator=(const CPUFramebuffer& other) = delete; + + uint32_t width() const { return m_width; } + uint32_t height() const { return m_height; } + + PixelFormat format() const { return m_format; } + unsigned num_planes() const { return m_num_planes; } + + uint32_t stride(unsigned plane) const { return m_planes[plane].stride; } + uint32_t size(unsigned plane) const { return m_planes[plane].size; } + uint32_t offset(unsigned plane) const { return m_planes[plane].offset; } + uint8_t* map(unsigned plane) { return m_planes[plane].map; } + +private: + struct FramebufferPlane { + uint32_t size; + uint32_t stride; + uint32_t offset; + uint8_t *map; + }; + + uint32_t m_width; + uint32_t m_height; + PixelFormat m_format; + + unsigned m_num_planes; + struct FramebufferPlane m_planes[4]; +}; + +} diff --git a/libkms++util/extcpuframebuffer.cpp b/libkms++util/extcpuframebuffer.cpp new file mode 100644 index 0000000..145168f --- /dev/null +++ b/libkms++util/extcpuframebuffer.cpp @@ -0,0 +1,50 @@ + +#include "extcpuframebuffer.h" +#include "test.h" + +using namespace std; + +namespace kms +{ + +ExtCPUFramebuffer::ExtCPUFramebuffer(uint32_t width, uint32_t height, PixelFormat format, + uint8_t* buffer, uint32_t pitch) + : m_width(width), m_height(height), m_format(format) +{ + const PixelFormatInfo& format_info = get_pixel_format_info(m_format); + + m_num_planes = format_info.num_planes; + + ASSERT(m_num_planes == 1); + + const PixelFormatPlaneInfo& pi = format_info.planes[0]; + FramebufferPlane& plane = m_planes[0]; + + plane.stride = pitch; + plane.size = plane.stride * height / pi.ysub; + plane.map = buffer; +} + +ExtCPUFramebuffer::ExtCPUFramebuffer(uint32_t width, uint32_t height, PixelFormat format, + uint8_t* buffers[4], uint32_t pitches[4]) + : m_width(width), m_height(height), m_format(format) +{ + const PixelFormatInfo& format_info = get_pixel_format_info(m_format); + + m_num_planes = format_info.num_planes; + + for (unsigned i = 0; i < format_info.num_planes; ++i) { + const PixelFormatPlaneInfo& pi = format_info.planes[i]; + FramebufferPlane& plane = m_planes[i]; + + plane.stride = pitches[i]; + plane.size = plane.stride * height / pi.ysub; + plane.map = buffers[i]; + } +} + +ExtCPUFramebuffer::~ExtCPUFramebuffer() +{ +} + +} diff --git a/libkms++util/extcpuframebuffer.h b/libkms++util/extcpuframebuffer.h new file mode 100644 index 0000000..172841f --- /dev/null +++ b/libkms++util/extcpuframebuffer.h @@ -0,0 +1,42 @@ +#pragma once + +#include "kms++.h" + +namespace kms +{ + +class ExtCPUFramebuffer : public IMappedFramebuffer +{ +public: + ExtCPUFramebuffer(uint32_t width, uint32_t height, PixelFormat format, + uint8_t* buffer, uint32_t pitch); + ExtCPUFramebuffer(uint32_t width, uint32_t height, PixelFormat format, + uint8_t* buffers[4], uint32_t pitches[4]); + virtual ~ExtCPUFramebuffer(); + + uint32_t width() const { return m_width; } + uint32_t height() const { return m_height; } + + PixelFormat format() const { return m_format; } + unsigned num_planes() const { return m_num_planes; } + + uint32_t stride(unsigned plane) const { return m_planes[plane].stride; } + uint32_t size(unsigned plane) const { return m_planes[plane].size; } + uint32_t offset(unsigned plane) const { return 0; } + uint8_t* map(unsigned plane) { return m_planes[plane].map; } + +private: + struct FramebufferPlane { + uint32_t size; + uint32_t stride; + uint8_t *map; + }; + + uint32_t m_width; + uint32_t m_height; + PixelFormat m_format; + + unsigned m_num_planes; + struct FramebufferPlane m_planes[4]; +}; +} diff --git a/libkms++util/kmstest.h b/libkms++util/kmstest.h new file mode 100644 index 0000000..aed40fe --- /dev/null +++ b/libkms++util/kmstest.h @@ -0,0 +1,15 @@ +#pragma once + +#include "color.h" +#include "framebuffer.h" + +namespace kms +{ +class IMappedFramebuffer; + +void draw_color_bar(IMappedFramebuffer& buf, int old_xpos, int xpos, int width); + +void draw_test_pattern(IMappedFramebuffer &fb); + +void draw_rect(IMappedFramebuffer &fb, uint32_t x, uint32_t y, uint32_t w, uint32_t h, RGB color); +} diff --git a/libkms++util/opts.cpp b/libkms++util/opts.cpp new file mode 100644 index 0000000..4ea31f8 --- /dev/null +++ b/libkms++util/opts.cpp @@ -0,0 +1,117 @@ +#include + +#include +#include + +#include "opts.h" + +using namespace std; + +Option::Option(const string& str, function func) + : m_void_func(func) +{ + parse(str); +} + +Option::Option(const string& str, function func) + : m_func(func) +{ + parse(str); +} + +void Option::parse(const string& str) +{ + auto iend = str.end(); + if (*(iend - 1) == '=') { + iend--; + m_has_arg = 1; + } else if (*(iend - 1) == '?') { + iend--; + m_has_arg = 2; + } else { + m_has_arg = 0; + } + + auto isplit = find(str.begin(), iend, '|'); + + if (isplit != str.begin()) + m_short = str[0]; + else + m_short = 0; + + if (isplit != iend) + m_long = string(isplit + 1, iend); +} + +OptionSet::OptionSet(initializer_list