diff options
| author | LI Qingwu <Qing-wu.Li@leica-geosystems.com.cn> | 2023-11-07 11:21:53 +0800 |
|---|---|---|
| committer | Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> | 2023-11-07 15:27:33 +0200 |
| commit | 412935a47b762c33e54a464243f2d789b065bbb6 (patch) | |
| tree | 6fe08d11cf4f34503f2a42d1e957ad8769d82f42 /py | |
| parent | 898a52f08482775776a08a99c33cb0458ec68977 (diff) | |
py: Framebuffer: Add map wrapping
Enables direct Python access to the framebuffer's buffer,
facilitating rapid image drawing capabilities.
Signed-off-by: LI Qingwu <Qing-wu.Li@leica-geosystems.com.cn>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Diffstat (limited to 'py')
| -rw-r--r-- | py/pykms/pykmsbase.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/py/pykms/pykmsbase.cpp b/py/pykms/pykmsbase.cpp index 7484770..254dce6 100644 --- a/py/pykms/pykmsbase.cpp +++ b/py/pykms/pykmsbase.cpp @@ -172,7 +172,18 @@ void init_pykmsbase(py::module& m) // Note that this means that python thinks we don't derive from DrmObject .def_property_readonly("id", &DrmObject::id) .def_property_readonly("idx", &DrmObject::idx) - .def_property_readonly("card", &DrmObject::card); + .def_property_readonly("card", &DrmObject::card) + .def("map", [](Framebuffer& self, uint32_t plane) { + const auto& format_info = get_pixel_format_info(self.format()); + + if (plane >= format_info.num_planes) + throw runtime_error("map: bad plane number"); + + array<uint32_t, 2> shape{ self.height(), self.width() * format_info.planes[plane].bitspp / 8 }; + array<uint32_t, 2> strides{ self.stride(plane), sizeof(uint8_t) }; + + return py::memoryview::from_buffer(self.map(plane), shape, strides); + }); py::class_<DumbFramebuffer, Framebuffer>(m, "DumbFramebuffer") .def(py::init<Card&, uint32_t, uint32_t, const string&>(), |
