summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomi Valkeinen <tomi.valkeinen@ti.com>2017-06-02 12:14:11 +0300
committerTomi Valkeinen <tomi.valkeinen@ti.com>2017-06-02 12:14:11 +0300
commitcb0786049f960f2bd383617151b01318e02e9ff9 (patch)
tree8dbce2679b0b87e9edf971efc87a05c1550d0ffb
parent719f72a065f07c59e77a25b1f23daccb5369cf81 (diff)
parent7450c364a57ec7d9e2abd61ac6e025c53e9e7a42 (diff)
Merge branch 'color-features' of git://github.com/jsarha/kmsxx
-rw-r--r--kms++util/inc/kms++util/color.h12
-rw-r--r--kms++util/inc/kms++util/kms++util.h2
-rw-r--r--kms++util/src/color.cpp74
-rw-r--r--kms++util/src/testpat.cpp18
-rw-r--r--py/pykms/pykmsbase.cpp3
-rw-r--r--py/pykms/pykmsutil.cpp10
-rwxr-xr-xpy/tests/ctm_test.py86
-rwxr-xr-xpy/tests/plane_csc.py66
8 files changed, 243 insertions, 28 deletions
diff --git a/kms++util/inc/kms++util/color.h b/kms++util/inc/kms++util/color.h
index ba2ed25..f378433 100644
--- a/kms++util/inc/kms++util/color.h
+++ b/kms++util/inc/kms++util/color.h
@@ -6,6 +6,14 @@ namespace kms
{
struct YUV;
+enum class YUVType {
+ BT601_Lim = 0,
+ BT601_Full,
+ BT709_Lim,
+ BT709_Full,
+ MAX,
+};
+
struct RGB
{
RGB();
@@ -19,7 +27,7 @@ struct RGB
uint32_t abgr8888() const;
uint16_t rgb565() const;
uint16_t bgr565() const;
- YUV yuv() const;
+ YUV yuv(YUVType type = YUVType::BT601_Lim) const;
uint8_t b;
uint8_t g;
@@ -31,7 +39,7 @@ struct YUV
{
YUV();
YUV(uint8_t y, uint8_t u, uint8_t v);
- YUV(const RGB& rgb);
+ YUV(const RGB& rgb, YUVType type = YUVType::BT601_Lim);
uint8_t v;
uint8_t u;
diff --git a/kms++util/inc/kms++util/kms++util.h b/kms++util/inc/kms++util/kms++util.h
index c1e3c8c..d45497e 100644
--- a/kms++util/inc/kms++util/kms++util.h
+++ b/kms++util/inc/kms++util/kms++util.h
@@ -26,7 +26,7 @@ void draw_text(IMappedFramebuffer& buf, uint32_t x, uint32_t y, const std::strin
void draw_color_bar(IMappedFramebuffer& buf, int old_xpos, int xpos, int width);
-void draw_test_pattern(IMappedFramebuffer &fb);
+void draw_test_pattern(IMappedFramebuffer &fb, YUVType yuvt = YUVType::BT601_Lim);
}
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
diff --git a/kms++util/src/color.cpp b/kms++util/src/color.cpp
index ae8a4b4..2e6f217 100644
--- a/kms++util/src/color.cpp
+++ b/kms++util/src/color.cpp
@@ -59,11 +59,40 @@ uint16_t RGB::bgr565() const
return ((b >> 3) << 11) | ((g >> 2) << 5) | ((r >> 3) << 0);
}
-YUV RGB::yuv() const
-{
- return YUV(*this);
-}
-
+YUV RGB::yuv(YUVType type) const
+{
+ return YUV(*this, type);
+}
+
+#define CF_ONE (256)
+#define CF(a, b, c) { ((int) ((a) * CF_ONE)), ((int) ((b) * CF_ONE)), ((int) ((c) * CF_ONE)) }
+#define CLAMP(a) ((a) > (CF_ONE-1) ? (CF_ONE-1) : (a) < 0 ? 0 : (a))
+
+const int YUVcoef[static_cast<unsigned>(YUVType::MAX)][3][3] = {
+ [static_cast<unsigned>(YUVType::BT601_Lim)] = {
+ CF( 0.257, 0.504, 0.098),
+ CF(-0.148, -0.291, 0.439),
+ CF( 0.439, -0.368, -0.071) },
+ [static_cast<unsigned>(YUVType::BT601_Full)] = {
+ CF( 0.299, 0.587, 0.114),
+ CF(-0.169, -0.331, 0.500),
+ CF( 0.500, -0.419, -0.081) },
+ [static_cast<unsigned>(YUVType::BT709_Lim)] = {
+ CF( 0.1826, 0.6142, 0.0620),
+ CF(-0.1006, -0.3386, 0.4392),
+ CF( 0.4392, -0.3989, -0.0403) },
+ [static_cast<unsigned>(YUVType::BT709_Full)] = {
+ CF( 0.2126, 0.7152, 0.0722),
+ CF(-0.1146, -0.3854, 0.5000),
+ CF( 0.5000, -0.4542, -0.0468) },
+};
+
+const int YUVoffset[static_cast<unsigned>(YUVType::MAX)][3] = {
+ [static_cast<unsigned>(YUVType::BT601_Lim)] = CF(0.0625, 0.5, 0.5),
+ [static_cast<unsigned>(YUVType::BT601_Full)] = CF( 0, 0.5, 0.5),
+ [static_cast<unsigned>(YUVType::BT709_Lim)] = CF(0.0625, 0.5, 0.5),
+ [static_cast<unsigned>(YUVType::BT709_Full)] = CF( 0, 0.5, 0.5),
+};
YUV::YUV()
{
@@ -78,26 +107,41 @@ YUV::YUV(uint8_t y, uint8_t u, uint8_t v)
this->a = 0;
}
-static inline uint8_t MAKE_YUV_601_Y(uint8_t r, uint8_t g, uint8_t b)
+static inline
+uint8_t MAKE_YUV_Y(uint8_t r, uint8_t g, uint8_t b, YUVType type)
{
- return (((66 * r + 129 * g + 25 * b + 128) >> 8) + 16);
+ unsigned tidx = static_cast<unsigned>(type);
+
+ return CLAMP(((YUVcoef[tidx][0][0] * r + YUVcoef[tidx][0][1] * g +
+ YUVcoef[tidx][0][2] * b + CF_ONE/2) / CF_ONE) +
+ YUVoffset[tidx][0]);
}
-static inline uint8_t MAKE_YUV_601_U(uint8_t r, uint8_t g, uint8_t b)
+static inline
+uint8_t MAKE_YUV_U(uint8_t r, uint8_t g, uint8_t b, YUVType type)
{
- return (((-38 * r - 74 * g + 112 * b + 128) >> 8) + 128);
+ unsigned tidx = static_cast<unsigned>(type);
+
+ return CLAMP(((YUVcoef[tidx][1][0] * r + YUVcoef[tidx][1][1] * g +
+ YUVcoef[tidx][1][2] * b + CF_ONE/2) / CF_ONE) +
+ YUVoffset[tidx][1]);
}
-static inline uint8_t MAKE_YUV_601_V(uint8_t r, uint8_t g, uint8_t b)
+static inline
+uint8_t MAKE_YUV_V(uint8_t r, uint8_t g, uint8_t b, YUVType type)
{
- return (((112 * r - 94 * g - 18 * b + 128) >> 8) + 128);
+ unsigned tidx = static_cast<unsigned>(type);
+
+ return CLAMP(((YUVcoef[tidx][2][0] * r + YUVcoef[tidx][2][1] * g +
+ YUVcoef[tidx][2][2] * b + CF_ONE/2) / CF_ONE) +
+ YUVoffset[tidx][2]);
}
-YUV::YUV(const RGB& rgb)
+YUV::YUV(const RGB& rgb, YUVType type)
{
- 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->y = MAKE_YUV_Y(rgb.r, rgb.g, rgb.b, type);
+ this->u = MAKE_YUV_U(rgb.r, rgb.g, rgb.b, type);
+ this->v = MAKE_YUV_V(rgb.r, rgb.g, rgb.b, type);
this->a = rgb.a;
}
}
diff --git a/kms++util/src/testpat.cpp b/kms++util/src/testpat.cpp
index fbe3b2e..dbd8fe6 100644
--- a/kms++util/src/testpat.cpp
+++ b/kms++util/src/testpat.cpp
@@ -97,7 +97,7 @@ static RGB get_test_pattern_pixel(IMappedFramebuffer& fb, unsigned x, unsigned y
}
}
-static void draw_test_pattern_part(IMappedFramebuffer& fb, unsigned start_y, unsigned end_y)
+static void draw_test_pattern_part(IMappedFramebuffer& fb, unsigned start_y, unsigned end_y, YUVType yuvt)
{
unsigned x, y;
unsigned w = fb.width();
@@ -127,7 +127,7 @@ static void draw_test_pattern_part(IMappedFramebuffer& fb, unsigned start_y, uns
for (x = 0; x < w; x += 2) {
RGB pixel1 = get_test_pattern_pixel(fb, x, y);
RGB pixel2 = get_test_pattern_pixel(fb, x + 1, y);
- draw_yuv422_macropixel(fb, x, y, pixel1.yuv(), pixel2.yuv());
+ draw_yuv422_macropixel(fb, x, y, pixel1.yuv(yuvt), pixel2.yuv(yuvt));
}
}
break;
@@ -141,8 +141,8 @@ static void draw_test_pattern_part(IMappedFramebuffer& fb, unsigned start_y, uns
RGB pixel01 = get_test_pattern_pixel(fb, x, y + 1);
RGB pixel11 = get_test_pattern_pixel(fb, x + 1, y + 1);
draw_yuv420_macropixel(fb, x, y,
- pixel00.yuv(), pixel10.yuv(),
- pixel01.yuv(), pixel11.yuv());
+ pixel00.yuv(yuvt), pixel10.yuv(yuvt),
+ pixel01.yuv(yuvt), pixel11.yuv(yuvt));
}
}
break;
@@ -151,10 +151,10 @@ static void draw_test_pattern_part(IMappedFramebuffer& fb, unsigned start_y, uns
}
}
-static void draw_test_pattern_impl(IMappedFramebuffer& fb)
+static void draw_test_pattern_impl(IMappedFramebuffer& fb, YUVType yuvt)
{
if (fb.height() < 20) {
- draw_test_pattern_part(fb, 0, fb.height());
+ draw_test_pattern_part(fb, 0, fb.height(), yuvt);
return;
}
@@ -174,21 +174,21 @@ static void draw_test_pattern_impl(IMappedFramebuffer& fb)
if (n == num_threads - 1)
end = fb.height();
- workers.push_back(thread([&fb, start, end]() { draw_test_pattern_part(fb, start, end); }));
+ workers.push_back(thread([&fb, start, end, yuvt]() { draw_test_pattern_part(fb, start, end, yuvt); }));
}
for (thread& t : workers)
t.join();
}
-void draw_test_pattern(IMappedFramebuffer &fb)
+void draw_test_pattern(IMappedFramebuffer &fb, YUVType yuvt)
{
#ifdef DRAW_PERF_PRINT
Stopwatch sw;
sw.start();
#endif
- draw_test_pattern_impl(fb);
+ draw_test_pattern_impl(fb, yuvt);
#ifdef DRAW_PERF_PRINT
double us = sw.elapsed_us();
diff --git a/py/pykms/pykmsbase.cpp b/py/pykms/pykmsbase.cpp
index d013f1f..604e07c 100644
--- a/py/pykms/pykmsbase.cpp
+++ b/py/pykms/pykmsbase.cpp
@@ -33,6 +33,7 @@ void init_pykmsbase(py::module &m)
.def("get_prop_value", (uint64_t (DrmPropObject::*)(const string&) const)&DrmPropObject::get_prop_value)
.def("set_prop_value",(int (DrmPropObject::*)(const string&, uint64_t)) &DrmPropObject::set_prop_value)
.def("get_prop_value_as_blob", &DrmPropObject::get_prop_value_as_blob)
+ .def("get_prop", &DrmPropObject::get_prop)
;
py::class_<Connector, Connector*>(m, "Connector", py::base<DrmPropObject>())
@@ -50,6 +51,7 @@ void init_pykmsbase(py::module &m)
py::class_<Crtc, Crtc*>(m, "Crtc", py::base<DrmPropObject>())
.def("set_mode", &Crtc::set_mode)
+ .def("disable_mode", &Crtc::disable_mode)
.def("page_flip",
[](Crtc* self, Framebuffer& fb, py::object ob)
{
@@ -86,6 +88,7 @@ void init_pykmsbase(py::module &m)
py::class_<Property, Property*>(m, "Property", py::base<DrmObject>())
.def_property_readonly("name", &Property::name)
+ .def_property_readonly("enums", &Property::get_enums)
;
py::class_<Blob>(m, "Blob", py::base<DrmObject>())
diff --git a/py/pykms/pykmsutil.cpp b/py/pykms/pykmsutil.cpp
index cb09dea..a5a6041 100644
--- a/py/pykms/pykmsutil.cpp
+++ b/py/pykms/pykmsutil.cpp
@@ -40,9 +40,17 @@ void init_pykmstest(py::module &m)
py::arg("crtc"),
py::arg("format") = PixelFormat::Undefined)
;
+ py::enum_<YUVType>(m, "YUVType")
+ .value("BT601_Lim", YUVType::BT601_Lim)
+ .value("BT601_Full", YUVType::BT601_Full)
+ .value("BT709_Lim", YUVType::BT709_Lim)
+ .value("BT709_Full", YUVType::BT709_Full)
+ ;
// Use lambdas to handle IMappedFramebuffer
- m.def("draw_test_pattern", [](MappedFramebuffer& fb) { draw_test_pattern(fb); } );
+ m.def("draw_test_pattern", [](MappedFramebuffer& fb, YUVType yuvt) { draw_test_pattern(fb, yuvt); },
+ py::arg("fb"),
+ py::arg("yuvt") = YUVType::BT601_Lim);
m.def("draw_color_bar", [](MappedFramebuffer& fb, int old_xpos, int xpos, int width) {
draw_color_bar(fb, old_xpos, xpos, width);
} );
diff --git a/py/tests/ctm_test.py b/py/tests/ctm_test.py
new file mode 100755
index 0000000..7ceed6f
--- /dev/null
+++ b/py/tests/ctm_test.py
@@ -0,0 +1,86 @@
+#!/usr/bin/python3
+
+import sys
+import pykms
+
+def ctm_to_blob(ctm, card):
+ len=9
+ arr = bytearray(len*8)
+ view = memoryview(arr).cast("I")
+
+ for x in range(len):
+ i, d = divmod(ctm[x], 1)
+ if i < 0:
+ i = -i
+ sign = 1 << 31
+ else:
+ sign = 0
+ view[x * 2 + 0] = int(d * ((2 ** 32) - 1))
+ view[x * 2 + 1] = int(i) | sign
+ #print("%f = %08x.%08x" % (ctm[x], view[x * 2 + 1], view[x * 2 + 0]))
+
+ return pykms.Blob(card, arr);
+
+
+if len(sys.argv) > 1:
+ conn_name = sys.argv[1]
+else:
+ conn_name = ""
+
+card = pykms.Card()
+res = pykms.ResourceManager(card)
+conn = res.reserve_connector(conn_name)
+crtc = res.reserve_crtc(conn)
+mode = conn.get_default_mode()
+
+fb = pykms.DumbFramebuffer(card, mode.hdisplay, mode.vdisplay, "XR24");
+pykms.draw_test_pattern(fb);
+
+crtc.set_mode(conn, fb, mode)
+
+input("press enter to set normal ctm\n")
+
+ctm = [ 1.0, 0.0, 0.0,
+ 0.0, 1.0, 0.0,
+ 0.0, 0.0, 1.0 ]
+
+ctmb = ctm_to_blob(ctm, card)
+
+crtc.set_prop("CTM", ctmb.id)
+
+input("press enter to set new ctm\n")
+
+ctm = [ 0.0, 1.0, 0.0,
+ 0.0, 0.0, 1.0,
+ 1.0, 0.0, 0.0 ]
+
+ctmb = ctm_to_blob(ctm, card)
+
+crtc.set_prop("CTM", ctmb.id)
+
+print("r->b g->r b->g ctm active\n")
+
+input("press enter to set new ctm\n")
+
+ctm = [ 0.0, 0.0, 1.0,
+ 1.0, 0.0, 0.0,
+ 0.0, 1.0, 0.0 ]
+
+ctmb = ctm_to_blob(ctm, card)
+
+crtc.set_prop("CTM", ctmb.id)
+input("r->g g->b b->r ctm active\n")
+
+input("press enter to turn off the crtc\n")
+
+crtc.disable_mode()
+
+input("press enter to enable crtc again\n")
+
+crtc.set_mode(conn, fb, mode)
+
+input("press enter to remove ctm\n")
+
+crtc.set_prop("CTM", 0)
+
+input("press enter to exit\n")
diff --git a/py/tests/plane_csc.py b/py/tests/plane_csc.py
new file mode 100755
index 0000000..be92c00
--- /dev/null
+++ b/py/tests/plane_csc.py
@@ -0,0 +1,66 @@
+#!/usr/bin/python3
+
+import pykms
+
+card = pykms.Card()
+res = pykms.ResourceManager(card)
+conn = res.reserve_connector("HDMI")
+crtc = res.reserve_crtc(conn)
+mode = conn.get_default_mode()
+modeb = mode.to_blob(card)
+plane = res.reserve_generic_plane(crtc, pykms.PixelFormat.UYVY)
+#plane = res.reserve_generic_plane(crtc, pykms.PixelFormat.Undefined)
+
+print("Got plane %d %d" % (plane.idx, plane.id))
+
+fb = pykms.DumbFramebuffer(card, mode.hdisplay, mode.vdisplay, "UYVY");
+pykms.draw_test_pattern(fb);
+
+req = pykms.AtomicReq(card)
+req.add(conn, "CRTC_ID", crtc.id)
+req.add(crtc, {"ACTIVE": 1,
+ "MODE_ID": modeb.id})
+
+input("Press enter to enable crtc idx %d at %s" % (crtc.idx, conn.fullname))
+r = req.commit_sync(allow_modeset = True)
+
+input("Press enter to enable plane idx %d at %s" % (plane.idx, conn.fullname))
+
+req = pykms.AtomicReq(card)
+req.add(plane, {"FB_ID": fb.id,
+ "CRTC_ID": crtc.id,
+ "SRC_X": 0 << 16,
+ "SRC_Y": 0 << 16,
+ "SRC_W": fb.width << 16,
+ "SRC_H": fb.height << 16,
+ "CRTC_X": 0,
+ "CRTC_Y": 0,
+ "CRTC_W": fb.width,
+ "CRTC_H": fb.height,
+ "zorder": 0})
+r = req.commit_sync()
+print("Plane enable request returned %d\n" % r)
+
+yuv_types = [pykms.YUVType.BT601_Lim,
+ pykms.YUVType.BT601_Full,
+ pykms.YUVType.BT709_Lim,
+ pykms.YUVType.BT709_Full]
+
+encoding_enums = plane.get_prop("COLOR_ENCODING").enums
+range_enums = plane.get_prop("COLOR_RANGE").enums
+
+for i in range(0, 2):
+ for j in range(0, 2):
+ input("press enter to for encoding: \"%s\" range: \"%s\"\n" %
+ (encoding_enums[i], range_enums[j]))
+
+ req = pykms.AtomicReq(card)
+ req.add(plane, {"COLOR_ENCODING": i,
+ "COLOR_RANGE": j})
+ req.commit_sync()
+
+ for t in yuv_types:
+ input("press enter to redraw with yuv_type %s\n" % t)
+ pykms.draw_test_pattern(fb, t);
+
+input("press enter to exit\n")