From patchwork Mon May 16 14:10:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 15917 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id EB632C326F for ; Mon, 16 May 2022 14:11:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9E40F65679; Mon, 16 May 2022 16:11:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1652710262; bh=h3HTxTU84cyLpKuYECAq/ub53xCYyQhLdSJVIez0dRk=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=u/ZLjW83PCp30ZfNah6gMQheEt+OOJJWSLc0cZTQe8Mg8XDfrjfPOc5o66vkJhMuw uU7weD+bTNyu9pIcxvMmEoc5/w1i2jhftvQqy+qnH+9uyRj8O1AAfgO2g9HBa27PX7 Jm82i8t7jzXn4rA0CJ/cU60TBg8NpUAbFJt+JZfGGPtYMh8FZx7YtSqOPkik1bioMu DKNeve8A8gcZswF7k6OqnrdV8yxnaxHhqeR5Z2qHf1yCjUY6+Pwpqpbk6BifkKQvw9 tJ8HN/vxV5e6oQSfh7ASD7rKGXIds8Y35X6y/iUe2hwZEaJeosAKn6Ncw1kp+G20ln 8cgcDfjf+lmlA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 853B16565D for ; Mon, 16 May 2022 16:10:53 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="MwZg0L26"; dkim-atps=neutral Received: from deskari.lan (91-156-85-209.elisa-laajakaista.fi [91.156.85.209]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 01EF0898; Mon, 16 May 2022 16:10:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1652710253; bh=h3HTxTU84cyLpKuYECAq/ub53xCYyQhLdSJVIez0dRk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MwZg0L26VHM0fCydYo51bPvb0JsNNZ4ST8Fc/vV4sGfg8wcf8oipzdpy91FA4qIft UUKdP9f579YKfH5UjPFvqt8HovIjYIty3r1NNzQYY4tR7jLTtyHvR7sOIJPMPkBBzx dwz8ESMK3THWjpwrFlGGqBce+iCIx+pjk0Qvl7jI= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Mon, 16 May 2022 17:10:19 +0300 Message-Id: <20220516141022.96327-12-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220516141022.96327-1-tomi.valkeinen@ideasonboard.com> References: <20220516141022.96327-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 11/14] py: add geometry classes X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tomi Valkeinen via libcamera-devel From: Tomi Valkeinen Reply-To: Tomi Valkeinen Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add libcamera's geometry classes to the Python bindings. Note that this commit only adds the classes, but they are not used anywhere yet. Signed-off-by: Tomi Valkeinen --- src/py/libcamera/meson.build | 1 + src/py/libcamera/pygeometry.cpp | 104 ++++++++++++++++++++++++++++++++ src/py/libcamera/pymain.cpp | 2 + 3 files changed, 107 insertions(+) create mode 100644 src/py/libcamera/pygeometry.cpp diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build index af8ba6a5..12e006e7 100644 --- a/src/py/libcamera/meson.build +++ b/src/py/libcamera/meson.build @@ -14,6 +14,7 @@ pybind11_dep = pybind11_proj.get_variable('pybind11_dep') pycamera_sources = files([ 'pyenums.cpp', + 'pygeometry.cpp', 'pymain.cpp', ]) diff --git a/src/py/libcamera/pygeometry.cpp b/src/py/libcamera/pygeometry.cpp new file mode 100644 index 00000000..2cd1432e --- /dev/null +++ b/src/py/libcamera/pygeometry.cpp @@ -0,0 +1,104 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Tomi Valkeinen + * + * Python bindings - Geometry classes + */ + +#include + +#include +#include + +#include +#include +#include + +namespace py = pybind11; + +using namespace libcamera; + +void init_py_geometry(py::module &m) +{ + py::class_(m, "Point") + .def(py::init<>()) + .def(py::init()) + .def_readwrite("x", &Point::x) + .def_readwrite("y", &Point::y) + .def(py::self == py::self) + .def(-py::self) + .def("__str__", &Point::toString) + .def("__repr__", [](const Point &self) { + return "libcamera.Point(" + std::to_string(self.x) + ", " + std::to_string(self.y) + ")"; + }); + + py::class_(m, "Size") + .def(py::init<>()) + .def(py::init()) + .def_readwrite("width", &Size::width) + .def_readwrite("height", &Size::height) + .def_property_readonly("is_null", &Size::isNull) + .def(py::self == py::self) + .def(py::self * float()) + .def(py::self / float()) + .def(py::self *= float()) + .def(py::self /= float()) + .def("__str__", &Size::toString) + .def("__repr__", [](const Size &self) { + return "libcamera.Size(" + std::to_string(self.width) + ", " + std::to_string(self.height) + ")"; + }); + + py::class_(m, "SizeRange") + .def(py::init<>()) + .def(py::init()) + .def(py::init()) + .def(py::init()) + .def(py::init<>([](const std::array &s) { + return SizeRange(Size(std::get<0>(s), std::get<1>(s))); + })) + .def(py::init<>([](const std::array &min, const std::array &max) { + return SizeRange(Size(std::get<0>(min), std::get<1>(min)), + Size(std::get<0>(max), std::get<1>(max))); + })) + .def(py::init<>([](const std::array &min, const std::array &max, + unsigned int hStep, unsigned int vStep) { + return SizeRange(Size(std::get<0>(min), std::get<1>(min)), + Size(std::get<0>(max), std::get<1>(max)), + hStep, vStep); + })) + .def_readwrite("min", &SizeRange::min) + .def_readwrite("max", &SizeRange::max) + .def_readwrite("hStep", &SizeRange::hStep) + .def_readwrite("vStep", &SizeRange::vStep) + .def(py::self == py::self) + .def("__str__", &SizeRange::toString) + .def("__repr__", [](const SizeRange &self) { + return py::str("libcamera.SizeRange(({}, {}), ({}, {}), {}, {})") + .format(self.min.width, self.min.height, + self.max.width, self.max.height, + self.hStep, self.vStep); + }); + + py::class_(m, "Rectangle") + .def(py::init<>()) + .def(py::init()) + .def(py::init<>([](int x, int y, const std::array &s) { + return Rectangle(x, y, std::get<0>(s), std::get<1>(s)); + })) + .def(py::init()) + .def(py::init()) + .def_readwrite("x", &Rectangle::x) + .def_readwrite("y", &Rectangle::y) + .def_readwrite("width", &Rectangle::width) + .def_readwrite("height", &Rectangle::height) + .def_property_readonly("is_null", &Rectangle::isNull) + .def_property_readonly("center", &Rectangle::center) + .def_property_readonly("size", &Rectangle::size) + .def_property_readonly("topLeft", &Rectangle::topLeft) + .def(py::self == py::self) + .def("__str__", &Rectangle::toString) + .def("__repr__", [](const Rectangle &self) { + return py::str("libcamera.Rectangle({}, {}, {}, {})") + .format(self.x, self.y, self.width, self.height); + }); +} diff --git a/src/py/libcamera/pymain.cpp b/src/py/libcamera/pymain.cpp index cc2ddee5..1dd70d9c 100644 --- a/src/py/libcamera/pymain.cpp +++ b/src/py/libcamera/pymain.cpp @@ -137,11 +137,13 @@ static void handleRequestCompleted(Request *req) void init_pyenums(py::module &m); void init_pyenums_generated(py::module &m); +void init_py_geometry(py::module &m); PYBIND11_MODULE(_libcamera, m) { init_pyenums(m); init_pyenums_generated(m); + init_py_geometry(m); /* Forward declarations */