summaryrefslogtreecommitdiff
path: root/kms++util/inc
diff options
context:
space:
mode:
authorTomi Valkeinen <tomi.valkeinen@ti.com>2016-06-11 22:39:24 +0300
committerTomi Valkeinen <tomi.valkeinen@ti.com>2016-06-11 22:41:01 +0300
commit3c6ea25bcfafc513560c9e8a4baaf211bec2750c (patch)
treeed8b174bb669c0012af28338def51efd808e61fb /kms++util/inc
parent9916712a62169606d845510028a3ea6f84bd442f (diff)
kms++util: split to subdirs
Diffstat (limited to 'kms++util/inc')
-rw-r--r--kms++util/inc/kms++util/color.h39
-rw-r--r--kms++util/inc/kms++util/cpuframebuffer.h44
-rw-r--r--kms++util/inc/kms++util/extcpuframebuffer.h42
-rw-r--r--kms++util/inc/kms++util/kms++util.h59
-rw-r--r--kms++util/inc/kms++util/opts.h38
-rw-r--r--kms++util/inc/kms++util/stopwatch.h28
-rw-r--r--kms++util/inc/kms++util/strhelpers.h33
7 files changed, 283 insertions, 0 deletions
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 <cstdint>
+
+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 <kms++/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/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 <kms++/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/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 <kms++/kms++.h>
+
+#include <kms++util/color.h>
+#include <kms++util/strhelpers.h>
+#include <kms++util/cpuframebuffer.h>
+#include <kms++util/extcpuframebuffer.h>
+#include <kms++util/stopwatch.h>
+#include <kms++util/opts.h>
+
+#include <cstdio>
+#include <cstdlib>
+
+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 <string>
+#include <vector>
+#include <functional>
+
+class Option
+{
+ friend class OptionSet;
+public:
+ Option(const std::string& str, std::function<void()> func);
+ Option(const std::string& str, std::function<void(const std::string)> func);
+
+private:
+ void parse(const std::string& str);
+
+ char m_short;
+ std::string m_long;
+ int m_has_arg;
+ std::function<void()> m_void_func;
+ std::function<void(const std::string)> m_func;
+};
+
+class OptionSet
+{
+public:
+ OptionSet(std::initializer_list<Option> il);
+
+ void parse(int argc, char** argv);
+
+ const std::vector<std::string> params() const { return m_params; }
+
+private:
+ const Option& find_opt(int c);
+
+ const std::vector<Option> m_opts;
+ std::vector<std::string> m_params;
+};
diff --git a/kms++util/inc/kms++util/stopwatch.h b/kms++util/inc/kms++util/stopwatch.h
new file mode 100644
index 0000000..9b60fa1
--- /dev/null
+++ b/kms++util/inc/kms++util/stopwatch.h
@@ -0,0 +1,28 @@
+#include <chrono>
+
+class Stopwatch
+{
+public:
+ void start()
+ {
+ m_start = std::chrono::steady_clock::now();
+ }
+
+ double elapsed_s() const
+ {
+ return std::chrono::duration<double>(std::chrono::steady_clock::now() - m_start).count();
+ }
+
+ double elapsed_ms() const
+ {
+ return std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - m_start).count();
+ }
+
+ double elapsed_us() const
+ {
+ return std::chrono::duration<double, std::micro>(std::chrono::steady_clock::now() - m_start).count();
+ }
+
+private:
+ std::chrono::steady_clock::time_point m_start;
+};
diff --git a/kms++util/inc/kms++util/strhelpers.h b/kms++util/inc/kms++util/strhelpers.h
new file mode 100644
index 0000000..2c540f3
--- /dev/null
+++ b/kms++util/inc/kms++util/strhelpers.h
@@ -0,0 +1,33 @@
+#include <sstream>
+#include <string>
+#include <vector>
+#include <functional>
+
+std::string to_lower(const std::string& str);
+
+template <typename T>
+std::string join(const T& values, const std::string& delim)
+{
+ std::ostringstream ss;
+ for (const auto& v : values) {
+ if (&v != &values[0])
+ ss << delim;
+ ss << v;
+ }
+ return ss.str();
+}
+
+template <typename T>
+std::string join(const std::vector<T>& values, const std::string& delim, std::function<std::string(T)> func)
+{
+ std::ostringstream ss;
+ for (const auto& v : values) {
+ if (&v != &values[0])
+ ss << delim;
+ ss << func(v);
+ }
+ return ss.str();
+}
+
+std::string sformat(const char *fmt, ...)
+ __attribute__ ((format (printf, 1, 2)));