From 3c6ea25bcfafc513560c9e8a4baaf211bec2750c Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Sat, 11 Jun 2016 22:39:24 +0300 Subject: kms++util: split to subdirs --- kms++util/inc/kms++util/color.h | 39 +++++++++++++++++++ kms++util/inc/kms++util/cpuframebuffer.h | 44 +++++++++++++++++++++ kms++util/inc/kms++util/extcpuframebuffer.h | 42 ++++++++++++++++++++ kms++util/inc/kms++util/kms++util.h | 59 +++++++++++++++++++++++++++++ kms++util/inc/kms++util/opts.h | 38 +++++++++++++++++++ kms++util/inc/kms++util/stopwatch.h | 28 ++++++++++++++ kms++util/inc/kms++util/strhelpers.h | 33 ++++++++++++++++ 7 files changed, 283 insertions(+) create mode 100644 kms++util/inc/kms++util/color.h create mode 100644 kms++util/inc/kms++util/cpuframebuffer.h create mode 100644 kms++util/inc/kms++util/extcpuframebuffer.h create mode 100644 kms++util/inc/kms++util/kms++util.h create mode 100644 kms++util/inc/kms++util/opts.h create mode 100644 kms++util/inc/kms++util/stopwatch.h create mode 100644 kms++util/inc/kms++util/strhelpers.h (limited to 'kms++util/inc') diff --git a/kms++util/inc/kms++util/color.h b/kms++util/inc/kms++util/color.h new file mode 100644 index 0000000..ef85a67 --- /dev/null +++ b/kms++util/inc/kms++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/kms++util/inc/kms++util/cpuframebuffer.h b/kms++util/inc/kms++util/cpuframebuffer.h new file mode 100644 index 0000000..1498528 --- /dev/null +++ b/kms++util/inc/kms++util/cpuframebuffer.h @@ -0,0 +1,44 @@ +#pragma once + +#include + +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/kms++util/inc/kms++util/extcpuframebuffer.h b/kms++util/inc/kms++util/extcpuframebuffer.h new file mode 100644 index 0000000..5d3be74 --- /dev/null +++ b/kms++util/inc/kms++util/extcpuframebuffer.h @@ -0,0 +1,42 @@ +#pragma once + +#include + +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/kms++util/inc/kms++util/kms++util.h b/kms++util/inc/kms++util/kms++util.h new file mode 100644 index 0000000..ca3c406 --- /dev/null +++ b/kms++util/inc/kms++util/kms++util.h @@ -0,0 +1,59 @@ +#pragma once + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace kms +{ +class IMappedFramebuffer; + +void draw_rgb_pixel(IMappedFramebuffer& buf, unsigned x, unsigned y, RGB color); +void draw_yuv422_macropixel(IMappedFramebuffer& buf, unsigned x, unsigned y, YUV yuv1, YUV yuv2); +void draw_yuv420_macropixel(IMappedFramebuffer& buf, unsigned x, unsigned y, + YUV yuv1, YUV yuv2, YUV yuv3, YUV yuv4); +void draw_rect(IMappedFramebuffer &fb, uint32_t x, uint32_t y, uint32_t w, uint32_t h, RGB color); +void draw_text(IMappedFramebuffer& buf, uint32_t x, uint32_t y, const std::string& str, RGB color); + +void draw_color_bar(IMappedFramebuffer& buf, int old_xpos, int xpos, int width); + +void draw_test_pattern(IMappedFramebuffer &fb); + +Connector* resolve_connector(Card& card, const std::string& str); +} + +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + +#define unlikely(x) __builtin_expect(!!(x), 0) + +#define ASSERT(x) \ + if (unlikely(!(x))) { \ + fprintf(stderr, "%s:%d: %s: ASSERT(%s) failed\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, __STRING(x)); \ + abort(); \ + } + +#define FAIL(fmt, ...) \ + do { \ + fprintf(stderr, "%s:%d: %s:\n" fmt "\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__); \ + abort(); \ + } while(0) + +#define FAIL_IF(x, fmt, ...) \ + if (unlikely(x)) { \ + fprintf(stderr, "%s:%d: %s:\n" fmt "\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__); \ + abort(); \ + } + +#define EXIT(fmt, ...) \ + do { \ + fprintf(stderr, fmt "\n", ##__VA_ARGS__); \ + exit(-1); \ + } while(0) diff --git a/kms++util/inc/kms++util/opts.h b/kms++util/inc/kms++util/opts.h new file mode 100644 index 0000000..1b0fd22 --- /dev/null +++ b/kms++util/inc/kms++util/opts.h @@ -0,0 +1,38 @@ +#pragma once + +#include +#include +#include + +class Option +{ + friend class OptionSet; +public: + Option(const std::string& str, std::function func); + Option(const std::string& str, std::function func); + +private: + void parse(const std::string& str); + + char m_short; + std::string m_long; + int m_has_arg; + std::function m_void_func; + std::function m_func; +}; + +class OptionSet +{ +public: + OptionSet(std::initializer_list