From patchwork Mon May 16 14:10:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 15918 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 D0D20C326E for ; Mon, 16 May 2022 14:11:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 604E86567C; Mon, 16 May 2022 16:11:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1652710263; bh=qO9eZeY+UmGt+WPdTtX/QwrNzHBKP0FK3kHiLR9Xleo=; 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=l9BhMmOlCwLXotjb83LG04xPpewa082aY9bXdhqRAyv+d4sApqthr+9Up4uYxA8MS mZlDutP3RKNg2HwTXW8D4rAyzgiKASSLngATdN/H4YJQemjp6nm5LmBv1m/4IwldJ7 CEfeBioxXQh4MHPKIa6d++RIRQYUPy3AURt9rxJRKD2ZqIS40UIoQ3izwDKJWBG7I6 u+A7813TXTrKD5maHsvWuQCzcUTstgBKs+s4+Vx7KSAya3/R1UHIxQQXH4q6fi+zaI B8Cqo/FAD8/SaeYJvS/xLbF8j/yrGw2jVw3flzb5egsjd70zoU+o0g24j6CrtvVpHu YRKthF6Z2ApSA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1BBB561FB8 for ; Mon, 16 May 2022 16:10:54 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="DxZslWE/"; 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 80E8F48F; Mon, 16 May 2022 16:10:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1652710253; bh=qO9eZeY+UmGt+WPdTtX/QwrNzHBKP0FK3kHiLR9Xleo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DxZslWE/SwRBloosc1sELMO5ZDKyLl/RDXuwkkQoW0s76GDgsbc3cDIdJTWcm2xmC 9vZDoVBXRNphBuU8yrYjHGrXW1keT50ik++nacwIHuyfYfuKSIPTf7EMbunCEeVvyJ CztHX9hsuCfPYgl5qkirvkNYGnJuA7pcPPOzHLhA= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Mon, 16 May 2022 17:10:20 +0300 Message-Id: <20220516141022.96327-13-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 12/14] py: use 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" Now that we have proper geometry classes in the Python bindings, change the existing bindings and the .py files accordingly. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart --- src/py/cam/cam.py | 7 ++++-- src/py/cam/cam_kms.py | 3 ++- src/py/cam/cam_qt.py | 3 ++- src/py/cam/cam_qtgl.py | 3 ++- src/py/libcamera/pymain.cpp | 41 ++++++++-------------------------- src/py/libcamera/utils/conv.py | 4 ++-- 6 files changed, 22 insertions(+), 39 deletions(-) diff --git a/src/py/cam/cam.py b/src/py/cam/cam.py index 63c67126..347175b7 100755 --- a/src/py/cam/cam.py +++ b/src/py/cam/cam.py @@ -160,8 +160,11 @@ def configure(ctx): for idx, stream_opts in enumerate(streams): stream_config = camconfig.at(idx) - if 'width' in stream_opts and 'height' in stream_opts: - stream_config.size = (stream_opts['width'], stream_opts['height']) + if 'width' in stream_opts: + stream_config.size.width = stream_opts['width'] + + if 'height' in stream_opts: + stream_config.size.height = stream_opts['height'] if 'pixelformat' in stream_opts: stream_config.pixel_format = libcam.PixelFormat.from_name(stream_opts['pixelformat']) diff --git a/src/py/cam/cam_kms.py b/src/py/cam/cam_kms.py index 7d11564b..da3dd4e0 100644 --- a/src/py/cam/cam_kms.py +++ b/src/py/cam/cam_kms.py @@ -125,7 +125,8 @@ class KMSRenderer: }) for fb in ctx['allocator'].buffers(stream): - w, h = cfg.size + w = cfg.size.width + h = cfg.size.height stride = cfg.stride fd = fb.fd(0) drmfb = pykms.DmabufFramebuffer(self.card, w, h, fmt, diff --git a/src/py/cam/cam_qt.py b/src/py/cam/cam_qt.py index 64f49f33..8bef9b57 100644 --- a/src/py/cam/cam_qt.py +++ b/src/py/cam/cam_qt.py @@ -136,7 +136,8 @@ class MainWindow(QtWidgets.QWidget): def buf_to_qpixmap(self, stream, fb): with fb.mmap() as mfb: cfg = stream.configuration - w, h = cfg.size + w = cfg.size.width + h = cfg.size.height pitch = cfg.stride if cfg.pixel_format.name == 'MJPEG': diff --git a/src/py/cam/cam_qtgl.py b/src/py/cam/cam_qtgl.py index 261accb8..4bbcda6c 100644 --- a/src/py/cam/cam_qtgl.py +++ b/src/py/cam/cam_qtgl.py @@ -268,7 +268,8 @@ class MainWindow(QtWidgets.QWidget): def create_texture(self, stream, fb): cfg = stream.configuration fmt = cfg.pixel_format.fourcc - w, h = cfg.size + w = cfg.size.width + h = cfg.size.height attribs = [ EGL_WIDTH, w, diff --git a/src/py/libcamera/pymain.cpp b/src/py/libcamera/pymain.cpp index 1dd70d9c..d7bd71ef 100644 --- a/src/py/libcamera/pymain.cpp +++ b/src/py/libcamera/pymain.cpp @@ -6,7 +6,6 @@ */ /* - * \todo Add geometry classes (Point, Rectangle...) * \todo Add bindings for the ControlInfo class */ @@ -61,11 +60,11 @@ static py::object controlValueToPy(const ControlValue &cv) return py::cast(cv.get()); case ControlTypeRectangle: { const Rectangle *v = reinterpret_cast(cv.data().data()); - return py::make_tuple(v->x, v->y, v->width, v->height); + return py::cast(v); } case ControlTypeSize: { const Size *v = reinterpret_cast(cv.data().data()); - return py::make_tuple(v->width, v->height); + return py::cast(v); } case ControlTypeNone: default: @@ -99,14 +98,10 @@ static ControlValue pyToControlValue(const py::object &ob, ControlType type) return controlValueMaybeArray(ob); case ControlTypeString: return ControlValue(ob.cast()); - case ControlTypeRectangle: { - auto array = ob.cast>(); - return ControlValue(Rectangle(array[0], array[1], array[2], array[3])); - } - case ControlTypeSize: { - auto array = ob.cast>(); - return ControlValue(Size(array[0], array[1])); - } + case ControlTypeRectangle: + return ControlValue(ob.cast()); + case ControlTypeSize: + return ControlValue(ob.cast()); case ControlTypeNone: default: throw std::runtime_error("Control type not implemented"); @@ -397,15 +392,7 @@ PYBIND11_MODULE(_libcamera, m) .def("__str__", &StreamConfiguration::toString) .def_property_readonly("stream", &StreamConfiguration::stream, py::return_value_policy::reference_internal) - .def_property( - "size", - [](StreamConfiguration &self) { - return std::make_tuple(self.size.width, self.size.height); - }, - [](StreamConfiguration &self, std::tuple size) { - self.size.width = std::get<0>(size); - self.size.height = std::get<1>(size); - }) + .def_readwrite("size", &StreamConfiguration::size) .def_readwrite("pixel_format", &StreamConfiguration::pixelFormat) .def_readwrite("stride", &StreamConfiguration::stride) .def_readwrite("frame_size", &StreamConfiguration::frameSize) @@ -416,18 +403,8 @@ PYBIND11_MODULE(_libcamera, m) pyStreamFormats .def_property_readonly("pixel_formats", &StreamFormats::pixelformats) - .def("sizes", [](StreamFormats &self, const PixelFormat &pixelFormat) { - std::vector> fmts; - for (const auto &s : self.sizes(pixelFormat)) - fmts.push_back(std::make_tuple(s.width, s.height)); - return fmts; - }) - .def("range", [](StreamFormats &self, const PixelFormat &pixelFormat) { - const auto &range = self.range(pixelFormat); - return make_tuple(std::make_tuple(range.hStep, range.vStep), - std::make_tuple(range.min.width, range.min.height), - std::make_tuple(range.max.width, range.max.height)); - }); + .def("sizes", &StreamFormats::sizes) + .def("range", &StreamFormats::range); pyFrameBufferAllocator .def(py::init>(), py::keep_alive<1, 2>()) diff --git a/src/py/libcamera/utils/conv.py b/src/py/libcamera/utils/conv.py index 30f6733e..5a4bc282 100644 --- a/src/py/libcamera/utils/conv.py +++ b/src/py/libcamera/utils/conv.py @@ -73,8 +73,8 @@ def demosaic(data, r0, g0, g1, b0): def to_rgb(fmt, size, data): - w = size[0] - h = size[1] + w = size.width + h = size.height fmt = fmt.name