Skip to content

Commit

Permalink
py: Framebuffer: Add map wrapping
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Qingwu-Li authored and tomba committed Nov 7, 2023
1 parent 898a52f commit 412935a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion py/pykms/pykmsbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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&>(),
Expand Down

0 comments on commit 412935a

Please sign in to comment.