From patchwork Wed May 18 13:13:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 15951 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 289A3C3256 for ; Wed, 18 May 2022 13:13:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5C4EF65663; Wed, 18 May 2022 15:13:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1652879630; bh=ZZ3IDxHSC+qdd3HzZK6lk4fjRtDB/Dtp8IClxoFVDOQ=; 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=NS2PPiSUeoQggmgth1rorET1Ta8e+GBGRk8Njmp9kgsvtReqJHjU5O5q+OxPSWO++ 7qprC3Ikbve4Cw8skXfaOoy2KS6dVNOvjVHfOPbsK8oPOG9+QFgPumUzZ1O4Asje5T 5c8EbF3ZzmgKsKcB0LjuzSHks2xSacb7pMEEG+coFPqZax/5qqyRa4IL5pdQEODgEv FXfMQUIfky4lNxQiIR3a81hYJFiWG6kDQcDs5yd98VA37A5ysyNqMQy4SmBlVHc0Q9 iMzbxxvc6MtI4vD+8tG3wvQGpphuK4c4BfaMmBe0V70v+Bw1JjxulNPCsVwMVCnyZI eFNDgyIQCuE7Q== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D5FD565656 for ; Wed, 18 May 2022 15:13:46 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="tQbOtn8r"; 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 4DBCF1027; Wed, 18 May 2022 15:13:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1652879626; bh=ZZ3IDxHSC+qdd3HzZK6lk4fjRtDB/Dtp8IClxoFVDOQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tQbOtn8rw+p0jSEeCEJGNDu8DVZBwonnG/c6vVV1yFPSGhZye2MCvN0F5/QsJyO/L kIhKGCptC0J5SoZAhVEoRjcQmWuNIeoyacFaoaN/7UUjCoTeGv/7tlKvMqTPN0DtY4 fm+I2kKSzrK6sAP9hrZK+pxb0Yi/7M/P35TDnITc= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Wed, 18 May 2022 16:13:12 +0300 Message-Id: <20220518131329.66994-2-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> References: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 01/18] py: meson: use files() for custom_target input files 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" Use files() for the input files for the custom_target(). I believe the current code works, but perhaps it is safer to use files() here. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/py/libcamera/meson.build | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build index 2fc2eaec..cd20bb00 100644 --- a/src/py/libcamera/meson.build +++ b/src/py/libcamera/meson.build @@ -17,10 +17,10 @@ pycamera_sources = files([ 'pymain.cpp', ]) -gen_input_files = [ - meson.project_source_root() / 'src' / 'libcamera' / 'control_ids.yaml', +gen_input_files = files([ + '../../libcamera/control_ids.yaml', 'pyenums_generated.cpp.in', -] +]) gen_py_control_enums = files('gen-py-control-enums.py') From patchwork Wed May 18 13:13:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 15952 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 F175CC3256 for ; Wed, 18 May 2022 13:13:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9D2B96566B; Wed, 18 May 2022 15:13:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1652879631; bh=Fsyv7aFRzZxb2py8kwU39x3o8yCDzH5TjggYy9i3e10=; 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=yT6l1D1ZOLAWUYfzfcgcTtXH0qSme7H8CexP40Zrh5nNbtD/kEmljYMj7JheBqfwn Cs9tuGMaJfX6IjcI94PxxmKBQT74hBiRPponK2W34ajOekAjTWRymt3VMjBOXvfiNQ CMJCAj/3RUIUq+nsKmex9OOvEthDMiJukkkPxvmCBnytcLYDzeVrh9iiKb8l5RA/KY ooOxiwyU/M+4g+hJHJvvRWBx3RXN9o0ZcMcy3BDa53npQkmOdwc1EGt4x92lE4/9/V aSu6DjOl64ehAT7NDV6rC7/gA1VbIWyP0MQg4uUbWfb1DyzeTgat0ms+8Ex7H+Az/V P1YMUbiFGxTjA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6596865656 for ; Wed, 18 May 2022 15:13:47 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="DlYdwN2u"; 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 C7CAE1AAA; Wed, 18 May 2022 15:13:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1652879627; bh=Fsyv7aFRzZxb2py8kwU39x3o8yCDzH5TjggYy9i3e10=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DlYdwN2uhMQhSpFGtRk31rolQ2gxN1KL2L5BD3O2Ad82XEZigB6M/u1eezgeisJg2 Pyniwgl6ihEWlZkGbdIhiYH88Po05BmmjwfX9N3INXpUFqMbc5kHB6o/DPcCwqpacf +DiPMFTBIiGaT8ZiVuYrkVLzMVd+HXzr/RQJlMCU= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Wed, 18 May 2022 16:13:13 +0300 Message-Id: <20220518131329.66994-3-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> References: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 02/18] py: meson: fix comment about stubs 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" At least pyright seems to be able to use the stubs from the libcamera-stubs directory, so no need to copy the generated files. Adjust the comment accordingly. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/py/libcamera/meson.build | 1 - 1 file changed, 1 deletion(-) diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build index cd20bb00..3c0828b8 100644 --- a/src/py/libcamera/meson.build +++ b/src/py/libcamera/meson.build @@ -63,4 +63,3 @@ install_data(['__init__.py'], install_dir : destdir) # \todo Generate stubs when building. See https://peps.python.org/pep-0484/#stub-files # Note: Depends on pybind11-stubgen. To generate pylibcamera stubs: # $ PYTHONPATH=build/src/py pybind11-stubgen --no-setup-py -o build/src/py libcamera -# $ mv build/src/py/libcamera-stubs/* build/src/py/libcamera/ From patchwork Wed May 18 13:13:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 15954 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 703FEC3256 for ; Wed, 18 May 2022 13:13:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 95E5B65677; Wed, 18 May 2022 15:13:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1652879634; bh=e8GwuZ1+hql6DFczVVZA21/83X36EjaGca/9EKOONdU=; 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=fky4om7y7mL9b0qdROmGyXBgYme70iqTBIjOo4ttkLuxSWTG69cNqObkFxPKA0wxg BxH4s0gRUrpsakh6Upfp9jL9Ppb77q73FOo8YkzFBtvNlpEruLihQsquMWVFwhyb2+ W7DGEl3MgUzXaxJ5ZZQLJ3+OuqVsj8DiTN5cABrcDDW/7OrguAHOumvklfHagPdWrN ijzddQV84HMWOgwelSi7K17EDmTNsyFHNOtw5fw0/mcnRUmR82eL0xxxnB6VgUOyty aJyqnYOJcZWMbHyoXmlawQO7W4vLuox/ol5Azb/ueMXhHi58iwxopRYvtzTcASjH8H a8OKBfCr6bRKg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F09F265660 for ; Wed, 18 May 2022 15:13:47 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="GxBhuAkm"; 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 54A6E1BBB; Wed, 18 May 2022 15:13:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1652879627; bh=e8GwuZ1+hql6DFczVVZA21/83X36EjaGca/9EKOONdU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GxBhuAkm68AXp4Z+LmvzVEh30qzFY22Njum2d2TRCBA38CrkJsPzi0ZwlGVQX6b3W xOcF2CN1lkLbXNOZJ9kfDy/VmYVEM/WzGtNzSuIlv1melVRS/j5W4a76G+SZ0rSL+Z 2jQaudyLshlTWpLn8v+SMcwJWae6r1qpBWo5PDmY= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Wed, 18 May 2022 16:13:14 +0300 Message-Id: <20220518131329.66994-4-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> References: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 03/18] py: add comment about the symlinks 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 comment about the symlinks to clarify the purpose. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/py/libcamera/meson.build | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build index 3c0828b8..427716d7 100644 --- a/src/py/libcamera/meson.build +++ b/src/py/libcamera/meson.build @@ -54,6 +54,9 @@ pycamera = shared_module('_libcamera', dependencies : pycamera_deps, cpp_args : pycamera_args) +# Create symlinks from the build dir to the source dir so that we can use the +# Python module directly from the build dir. + run_command('ln', '-fsT', files('__init__.py'), meson.current_build_dir() / '__init__.py', check: true) From patchwork Wed May 18 13:13:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 15953 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 493E6C326C for ; Wed, 18 May 2022 13:13:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1EACA65674; Wed, 18 May 2022 15:13:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1652879634; bh=VF0PDQHKymghFB0VprBQomgf1P191nnk4IYyXXg6v5c=; 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=kE1q5EUjShm7Q/rIbLam/a97COob2eqHp8G4OWX6dQXfBvNhAJeleYQkjWgDefRtX PNCWnctUWe8J/q0eT0Pm/+RoB0XabDJbCckCOssCZAhkG5p+h0KvQCUAr57F33U9+k EwiNIADQbh2gt1J90w7yw7+93+m+OpGW+Im6rlcd6Ba5QHnOWBbTgy7dO0LonLEvit RkF8H0EOfA79+NDKazvMKYG79uf073n4GXqG2O1uxWkJI4cFRLj+7Pjo1PvUyZ80UH zPYg/P1H/14+SgAWXqbN3dXo5o45o3HQvN2GQP+lTEkQYU3v+dijpJ2exAASNciVXZ VB0KoyZsGcS2g== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C3B7D6565E for ; Wed, 18 May 2022 15:13:48 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="qpZYXQE3"; 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 DC5511BCD; Wed, 18 May 2022 15:13:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1652879628; bh=VF0PDQHKymghFB0VprBQomgf1P191nnk4IYyXXg6v5c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qpZYXQE3coxwFVXCEOBsjnXqSNaXxo5mcDZzeEGrr8dDsUjKhkJPcdjphB+fRRDgr UHJf14A5Ky4o3Uj9ui3izIyRs6I6Q6x7oD/BLjci1qOCFCnCEIA0ZcrgbQWafrWfRp 48m7j5BlV7Rb2pPXPLTcvnKon8E87EMB5/gPLWVM= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Wed, 18 May 2022 16:13:15 +0300 Message-Id: <20220518131329.66994-5-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> References: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 04/18] py: pymain: fix indent 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" Fix two minor mis-indents. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/py/libcamera/pymain.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/py/libcamera/pymain.cpp b/src/py/libcamera/pymain.cpp index fb89975c..af22205e 100644 --- a/src/py/libcamera/pymain.cpp +++ b/src/py/libcamera/pymain.cpp @@ -394,7 +394,7 @@ PYBIND11_MODULE(_libcamera, m) pyStreamConfiguration .def("__str__", &StreamConfiguration::toString) .def_property_readonly("stream", &StreamConfiguration::stream, - py::return_value_policy::reference_internal) + py::return_value_policy::reference_internal) .def_property( "size", [](StreamConfiguration &self) { @@ -416,7 +416,7 @@ PYBIND11_MODULE(_libcamera, m) .def_readwrite("frame_size", &StreamConfiguration::frameSize) .def_readwrite("buffer_count", &StreamConfiguration::bufferCount) .def_property_readonly("formats", &StreamConfiguration::formats, - py::return_value_policy::reference_internal) + py::return_value_policy::reference_internal) .def_readwrite("color_space", &StreamConfiguration::colorSpace); pyStreamFormats From patchwork Wed May 18 13:13:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 15955 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 B6375C326C for ; Wed, 18 May 2022 13:13:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0283865661; Wed, 18 May 2022 15:13:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1652879636; bh=RKi8ohSP2/H4tFlJm6FL57C1QuJSK4DqfYF2nMVFae4=; 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=ZWORPCRNnKvNpRUVlsTMZFCnB4fCC47BwtbQEdeyhL2bfeG3K8GB8PmCbR8yAw0VO p6rQeXVMn6BFZMjzTcgG76YxHehHimwbJgTsGyYCawUJSVRTUIrXCcxhbEPBcVrpuU hk/7CdKKKgGUrhV0xn5LWObHPnm9/KlFb2qfcMhU8abnnw29gYgmwpFMg3ivsYq30a oh1hfGGeRR0sub/V2vLZ8I6FxbF0XeA9w9x7Ab6laQontiYidWbo17oAsaS90EKVSi 2pH9k1pa7k3nSHyQnZw6JHJcpX2edjH5/3M+OCbMSyeLuDDH/cpKzle+9Uc6eSYIyh Sb9tbdbpWZNnA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 12F976565B for ; Wed, 18 May 2022 15:13:49 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="PRwMVjY/"; 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 634B41C03; Wed, 18 May 2022 15:13:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1652879628; bh=RKi8ohSP2/H4tFlJm6FL57C1QuJSK4DqfYF2nMVFae4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PRwMVjY/vmmphkZFBpBPvr4d2hT7X4lzL+GqisixBt44wdRly5TVdI8LzVNOpJhIh NbnKwxyFmO5sJb3rr1JmW1abjQrfa4qRlTxvzf1IAKaOgUBNmvSDfYLJv7k4tsUSKB nVQtIGXk0o7wt6l80lDmRRK+S+rLCJWqNd5zrWPU= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Wed, 18 May 2022 16:13:16 +0300 Message-Id: <20220518131329.66994-6-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> References: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 05/18] py: unittests: fix selector fd use 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" pyright complains about passing fileobj to os.read. Indeed, the parameter should be an int, but I guess fileobj gets automatically converted. In any case, using the fd is better. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- test/py/unittests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/py/unittests.py b/test/py/unittests.py index cbc00ff3..9326358d 100755 --- a/test/py/unittests.py +++ b/test/py/unittests.py @@ -262,8 +262,8 @@ class SimpleCaptureMethods(CameraTesterBase): running = True while running: events = sel.select() - for key, mask in events: - os.read(key.fileobj, 8) + for key, _ in events: + os.read(key.fd, 8) ready_reqs = cm.get_ready_requests() From patchwork Wed May 18 13:13:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 15956 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 A8238C326D for ; Wed, 18 May 2022 13:13:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 351EE6566E; Wed, 18 May 2022 15:13:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1652879637; bh=81cfyWdLmXwVC6nVNluygfhKfJMgfSkSf0jP/R91RlA=; 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=qqd/3E0P7CE61EJQDnKKPC38fYPpFob7ArlOYLqPguFgYfb0maRtM+T0OD7uK8AX3 wV+awMSfcy/2oLU8UWnn0H1AZCDVrw73uASjMJqZrzGLFQTaq67fGBpltks6nqxsZV 4d4HbhjuTG3sKEEOCGraMrp3RzqfvgdMsckMS/MpLR3kM82nl68yYZHvgAbizOeAH+ OCFQrAaVPo1NeWnZYiQbjrL4EhZWIUQqo0/RfB9aQZLQDJGufRSftxu1JwHh308IML Nzk3GNp2oaBFS+iBl26PB7morUB7s8lm8r3PIuzif/E6gzYe2TvAwA99zA8vvJcTa/ bdT3q9cIVcJxw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 78D6B65656 for ; Wed, 18 May 2022 15:13:49 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="tsTPgqv/"; 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 DF4111C13; Wed, 18 May 2022 15:13:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1652879629; bh=81cfyWdLmXwVC6nVNluygfhKfJMgfSkSf0jP/R91RlA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tsTPgqv/5P7aN1LYT+zHRZ7NujZluwuKRTVXsgwa7B/SVEOhQiFfeFpFANbF8fEmA vcw8Za5bbnz/WRMLVVkk/gm0hhf1U3MwWQkDvVaUDyC1U7jG6j6WXK2MpMK+pXjPzL l4nhYWoxwsFPqibDQFrwgHos9uxzFtIecNkyjEgg= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Wed, 18 May 2022 16:13:17 +0300 Message-Id: <20220518131329.66994-7-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> References: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 06/18] py: unittests: verify that cam and cm are freed 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 checks to CameraTesterBase to verify that both the Camera and the CameraManager gets freed. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- test/py/unittests.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/py/unittests.py b/test/py/unittests.py index 9326358d..4c214f0a 100755 --- a/test/py/unittests.py +++ b/test/py/unittests.py @@ -83,6 +83,9 @@ class CameraTesterBase(BaseTestCase): self.cm = None raise Exception('Failed to acquire camera') + self.wr_cam = weakref.ref(self.cam) + self.wr_cm = weakref.ref(self.cm) + def tearDown(self): # If a test fails, the camera may be in running state. So always stop. self.cam.stop() @@ -94,6 +97,9 @@ class CameraTesterBase(BaseTestCase): self.cam = None self.cm = None + self.assertIsNone(self.wr_cm()) + self.assertIsNone(self.wr_cam()) + class AllocatorTestMethods(CameraTesterBase): def test_allocator(self): From patchwork Wed May 18 13:13:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 15957 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 E375CC326E for ; Wed, 18 May 2022 13:14:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 674DA65671; Wed, 18 May 2022 15:13:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1652879639; bh=2Gh0dNLUngxfQES1Wrqv7GwQjtiauyJZZwFH21iSIM0=; 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=B5y2nZeN06WF2m/QzN2bKcSJm8Vj0QJBHCNM5DgLRZtkltjuBlQJiUlgNZD8/NG4Q aR9FcCFXXHSRzZnFXvn3bp/Sn2wkygmKLuQwk6uSkLqUAxpkzGt2HOBDrc7zMJBZjf xNBEz8tUu5PywIyi7yFPzSDq2UqEiWQzO1tdQUn6B6cFkFFaZM28FQoFIv6zYhHUxd C+iR/ETBEm8QCYJa3DTUjQY1w6n6eYvGx2QrKJnCehsb7wSngw8ugyLzMjw+y/4dDn 80Pbz5ZH0nr78k+gVj+mExcLHKi/shICRo27QGaI513O/cyerP2rsItvHqYk85cJD6 C3uB5kEhCemWA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 060AA65662 for ; Wed, 18 May 2022 15:13:50 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="lBnAv0C4"; 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 672DB1C19; Wed, 18 May 2022 15:13:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1652879629; bh=2Gh0dNLUngxfQES1Wrqv7GwQjtiauyJZZwFH21iSIM0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lBnAv0C4Nf/3wQYb9gUe6tKcQhRfFKtviDeiS0dkKOTTdimAati1p93YGU9FJ67IO ltr2SCF43IouZlQxz4QqweAGEaUKSqXn7aKVmZpQm4vy79a/P6/3mn7tmFqs7JLXcD f01YBCtVZKKJKsv2HG5V0cEpf9EFgUM4pnXZ4O5I= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Wed, 18 May 2022 16:13:18 +0300 Message-Id: <20220518131329.66994-8-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> References: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 07/18] py: unittests: make typechecker happy 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 some annotations and self.assertIsNotNone() calls to remove the typechecker warnings. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- test/py/unittests.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/test/py/unittests.py b/test/py/unittests.py index 4c214f0a..7dede33b 100755 --- a/test/py/unittests.py +++ b/test/py/unittests.py @@ -10,6 +10,7 @@ import libcamera as libcam import os import selectors import time +import typing import unittest import weakref @@ -70,6 +71,9 @@ class SimpleTestMethods(BaseTestCase): class CameraTesterBase(BaseTestCase): + cm: typing.Any + cam: typing.Any + def setUp(self): self.cm = libcam.CameraManager.singleton() self.cam = next((cam for cam in self.cm.cameras if 'platform/vimc' in cam.id), None) @@ -131,6 +135,7 @@ class AllocatorTestMethods(CameraTesterBase): wr_allocator = weakref.ref(allocator) buffers = allocator.buffers(stream) + self.assertIsNotNone(buffers) buffers = None buffer = allocator.buffers(stream)[0] @@ -166,6 +171,8 @@ class SimpleCaptureMethods(CameraTesterBase): streamconfig = camconfig.at(0) fmts = streamconfig.formats + self.assertIsNotNone(fmts) + fmts = None ret = cam.configure(camconfig) self.assertZero(ret) @@ -225,6 +232,8 @@ class SimpleCaptureMethods(CameraTesterBase): streamconfig = camconfig.at(0) fmts = streamconfig.formats + self.assertIsNotNone(fmts) + fmts = None ret = cam.configure(camconfig) self.assertZero(ret) @@ -348,9 +357,9 @@ if __name__ == '__main__': gc.unfreeze() gc.collect() - obs_after = get_all_objects([obs_before]) + obs_after = get_all_objects([obs_before]) # type: ignore - before = create_type_count_map(obs_before) + before = create_type_count_map(obs_before) # type: ignore after = create_type_count_map(obs_after) leaks = diff_type_count_maps(before, after) From patchwork Wed May 18 13:13: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: 15958 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 7D562C326F for ; Wed, 18 May 2022 13:14:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CBAF565683; Wed, 18 May 2022 15:14:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1652879643; bh=JZAVTew1P2MIk/cAWcOzxmQ+swz6krcVQuE6EV51mDc=; 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=pMx14f2ls4PXUmZcpmC/kL9GJD2yngA7kDn/NHRRrQPDzCu4FBdwFgNDLy04SGZsC tE89LY5Mrj0VMyYq5UGxQissZEB0HcpvanebYQa+U25EHHYrADRpn0N1ihpM3pj0tM 2mg4bAHxWMbZX/D9yFDZD7OOGUfq7zQrubiEP29+4fSdcPJxc22LhLsCRJgofmsoSc rv7SbozWrV4wnpqgUHpPokIhM3Gy0ys1XVHdKiZB4K6Fv3sPmU1JmOK0/bwqGme/cx 3oHP9aWk6ViernFYO67sHrWE7tUVswG2UTSBaAYMY4QRpxQgj18ZGB0TL/tdI2QDTs oSg+pvPdjUXRA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 73D2A65664 for ; Wed, 18 May 2022 15:13:50 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="eWcpjvdO"; 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 E551021CB; Wed, 18 May 2022 15:13:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1652879630; bh=JZAVTew1P2MIk/cAWcOzxmQ+swz6krcVQuE6EV51mDc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eWcpjvdOGHlgo2pqltvw4FCbzKkVF4vOLIyhaww1OeIMxlR6TQQHdKZ6f+nvE7udS CN2LvLtPBrXg/EFrJzre1jnGPo3tcVYkbNMhl4KtFCdJv+ZHRtQzf+ocZeYH7Fpz5p GfG6P7QlpNIOzKNdbH+TaLtb+hyMRAK6ykNqhlYo= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Wed, 18 May 2022 16:13:19 +0300 Message-Id: <20220518131329.66994-9-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> References: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 08/18] py: cam.py: exit on exception 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" Catch exceptions in the event_handler, as they would get ignored otherwise. Print the exception and return False so that the main loop exits. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/py/cam/cam.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/py/cam/cam.py b/src/py/cam/cam.py index 012b191c..c7da97d7 100755 --- a/src/py/cam/cam.py +++ b/src/py/cam/cam.py @@ -11,6 +11,7 @@ import binascii import libcamera as libcam import os import sys +import traceback class CustomAction(argparse.Action): @@ -286,19 +287,23 @@ def capture_start(contexts): # Called from renderer when there is a libcamera event def event_handler(state): - cm = state['cm'] - contexts = state['contexts'] + try: + cm = state['cm'] + contexts = state['contexts'] - os.read(cm.efd, 8) + os.read(cm.efd, 8) - reqs = cm.get_ready_requests() + reqs = cm.get_ready_requests() - for req in reqs: - ctx = next(ctx for ctx in contexts if ctx['idx'] == req.cookie) - request_handler(state, ctx, req) + for req in reqs: + ctx = next(ctx for ctx in contexts if ctx['idx'] == req.cookie) + request_handler(state, ctx, req) - running = any(ctx['reqs-completed'] < ctx['opt-capture'] for ctx in contexts) - return running + running = any(ctx['reqs-completed'] < ctx['opt-capture'] for ctx in contexts) + return running + except Exception as e: + traceback.print_exc() + return False def request_handler(state, ctx, req): From patchwork Wed May 18 13:13: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: 15959 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 E9B12C3270 for ; Wed, 18 May 2022 13:14:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6C3FB65673; Wed, 18 May 2022 15:14:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1652879644; bh=0E1l+zZJe89mXQfzY2FnvUcWOVVH+rL1DzyelJd/0Vs=; 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=MAuFdP+Im5QPo9GQuojDfXHf2yEFggE8Yz7aXcrvRqJIASONCa8HnRZqw6+JVFJ6Z IbE4BY3nzdjL7fprxUHcbvZ+JnIJir1B7jm5QUnX8KoiJKj7myX3ESKBzhyYbBPNFN 4XvnotM5Vyec2HkYrhpGaFL7SQqItdH97VpEKJjGbmX5yc4/iptjZZyiwQa/QE1iPs OzJkIeSUDIAgmaEWDfdECTL0VS78a5M75AwQxMaNJIA2D+EfcfXvzL1sRoeEmvJUoM NfJqw7c6VoJCHacJZuStIKXLEQeo+xNAaBGcai7rR2bT4MmQO5Yr/T5+KUW0B+J8Cg xFe+E4vLagZDw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 03DB265658 for ; Wed, 18 May 2022 15:13:51 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="NJAJNzXs"; 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 6D6ED21DB; Wed, 18 May 2022 15:13:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1652879630; bh=0E1l+zZJe89mXQfzY2FnvUcWOVVH+rL1DzyelJd/0Vs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NJAJNzXsFLR5IdYg8aomgwbZli8dHY+up9xYm1pySbrutLQHgMZYs1xKBWyjvzS6M dNlE1sRvKuPSSqC05/SmkerN1jtbdBZWvV+QvJVGYkXK9i11uE8Pnc6G3/7EIOzIMA arL743iZ2/O9WRAZDGZqlHySwnmDxYm4BFWtRnPM= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Wed, 18 May 2022 16:13:20 +0300 Message-Id: <20220518131329.66994-10-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> References: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 09/18] py: cam_kms: support multiplanar formats 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" Support multiplanar formats in the kms renderer. Tested with RPi and NV12. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/py/cam/cam_kms.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/py/cam/cam_kms.py b/src/py/cam/cam_kms.py index ae6be277..f1844717 100644 --- a/src/py/cam/cam_kms.py +++ b/src/py/cam/cam_kms.py @@ -10,6 +10,7 @@ FMT_MAP = { 'YUYV': pykms.PixelFormat.YUYV, 'ARGB8888': pykms.PixelFormat.ARGB8888, 'XRGB8888': pykms.PixelFormat.XRGB8888, + 'NV12': pykms.PixelFormat.NV12, } @@ -133,10 +134,16 @@ class KMSRenderer: for fb in ctx['allocator'].buffers(stream): w, h = cfg.size - stride = cfg.stride - fd = fb.fd(0) + fds = [] + strides = [] + offsets = [] + for i in range(fb.num_planes): + fds.append(fb.fd(i)) + strides.append(cfg.stride) + offsets.append(fb.offset(i)) + drmfb = pykms.DmabufFramebuffer(self.card, w, h, fmt, - [fd], [stride], [0]) + fds, strides, offsets) self.cam_2_drm[fb] = drmfb idx += 1 From patchwork Wed May 18 13:13:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 15960 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 B4103C3271 for ; Wed, 18 May 2022 13:14:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 260C365675; Wed, 18 May 2022 15:14:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1652879645; bh=kk3f22MHUK4RaU0Hou0Ocit2U5vTR7pWRoYQV7nTU8k=; 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=imh+drDrcDFgMktBwhbYeNQEOJ7j72eDtS2cdu/1OwEvqNOhNYJHPdAgsQ0cl4nsT WwHOqprt1bFXZ63b5xLeiMmcFO1ISSzMW/Rm35UwElU7XxJGqP2QJNFLr/cR2uS1Nr K+1LCWL2+h3XAqPJi4r6U1bT6+WHNHfMW7j7asNsxFP76etOWV7+rwXJFaD44tPN8Q 1dPp88gP/GQuwk5y1DWG+mhPD0Rm4F8HackQzM7huZ9qoxSUOIpaxZcEy5gSZheFwQ zmQvzKPqPKq88i9R1O6enC/beJ33tabeJWjyH5D0Soqq5aD9Vsz2/fSlD4Vuf6Inun /Lxx0sIpqF+KQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 84B0C6566A for ; Wed, 18 May 2022 15:13:51 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="EPKtiGT3"; 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 EB0F1E50; Wed, 18 May 2022 15:13:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1652879631; bh=kk3f22MHUK4RaU0Hou0Ocit2U5vTR7pWRoYQV7nTU8k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EPKtiGT3kzKKnfcrFXygcQSJzrRJH8U8GRTKKTgkfDXYwm5HCvcz4zp4Idh9e9G8n GS9haDS/5+EBPZdkZjNJXqToVIwiJ4JWGIDx1OY0ONLTspjcZRBZlcbLYvgvou/0Ko cQ0vywKmrI873vavz7lEjpmrIVADnXu/zzNQnhfY= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Wed, 18 May 2022 16:13:21 +0300 Message-Id: <20220518131329.66994-11-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> References: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 10/18] py: cam_kms: fix multistream display 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" Instead of doing an atomic commit for each stream, do a single commit for the two planes. This fixes the issue that only the first plane was actually shown. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/py/cam/cam_kms.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/py/cam/cam_kms.py b/src/py/cam/cam_kms.py index f1844717..d8ff0284 100644 --- a/src/py/cam/cam_kms.py +++ b/src/py/cam/cam_kms.py @@ -75,12 +75,13 @@ class KMSRenderer: buffers = drmreq['camreq'].buffers + req = pykms.AtomicReq(self.card) + for stream, fb in buffers.items(): drmfb = self.cam_2_drm.get(fb, None) - - req = pykms.AtomicReq(self.card) self.add_plane(req, stream, drmfb) - req.commit() + + req.commit() def handle_page_flip(self, frame, time): old = self.current From patchwork Wed May 18 13:13:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 15961 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 79B70C3272 for ; Wed, 18 May 2022 13:14:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E7DA165678; Wed, 18 May 2022 15:14:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1652879646; bh=el4gJmeSP+tx4hhxqvl52vgOFMAHhzI5MxrWGRX1n1M=; 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=gXYO9UfAjT61PfJMn2/FFrHoG2vonv2Pw+ZEZ6caOChdJDJRuZthK2B+/+zzfMCuZ FuGO3Tfhsqc1N08xCqY0OrCOE5tclytj7fp93YluQ2ZUkvOacpjUYcRQjkgZP5n1uV hex5UOANGbx9IM3YZ3Yn329OLhMORhO6fVZ2gIEo+NU+H8j4p6u/+ysTxiXH8x4Fco gE1RdF6smTF2UTDJ8NBoWabwRxTBsyDBWX8c7fxcxVYbEzOci4wH8VYF6EAeNOPEiO Gr/ECtw39OJXeRRqd8emOLT5SuNDIrSixql4R69fVr8jaum+acqdU/scmkY4iCyRJD oHOtofOcpS9mA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 00B1E6566D for ; Wed, 18 May 2022 15:13:52 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ZL/FTaAy"; 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 726D71027; Wed, 18 May 2022 15:13:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1652879631; bh=el4gJmeSP+tx4hhxqvl52vgOFMAHhzI5MxrWGRX1n1M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZL/FTaAyzF/EA+2QMlIYfISp/xXPS3azC3AT1kdhY1i9LAOuagmNSHsePGW6jFCG+ 217TtLQMJgHVVT7j37ADCkCbaTsOkQsOjQ8x5TG+jWY/szqQSPQb77if/F4RZDGWIu yUtE9Ej/K5UKRrV1eimjEZKRvSPVn3zrejxMF6cs= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Wed, 18 May 2022 16:13:22 +0300 Message-Id: <20220518131329.66994-12-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> References: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 11/18] py: cam_qt: cosmetic cleanups 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" Drop irrelevant or wrong comments, merge separate_components() into demosaic(), and add mfb_to_rgb(). No functional changes. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/py/cam/cam_qt.py | 64 +++++++++----------------------------------- 1 file changed, 13 insertions(+), 51 deletions(-) diff --git a/src/py/cam/cam_qt.py b/src/py/cam/cam_qt.py index 5753f0b2..fb485b9b 100644 --- a/src/py/cam/cam_qt.py +++ b/src/py/cam/cam_qt.py @@ -19,19 +19,8 @@ def rgb_to_pix(rgb): return pix -def separate_components(data, r0, g0, g1, b0): - # Now to split the data up into its red, green, and blue components. The - # Bayer pattern of the OV5647 sensor is BGGR. In other words the first - # row contains alternating green/blue elements, the second row contains - # alternating red/green elements, and so on as illustrated below: - # - # GBGBGBGBGBGBGB - # RGRGRGRGRGRGRG - # GBGBGBGBGBGBGB - # RGRGRGRGRGRGRG - # - # Please note that if you use vflip or hflip to change the orientation - # of the capture, you must flip the Bayer pattern accordingly +def demosaic(data, r0, g0, g1, b0): + # Separate the components from the Bayer data to RGB planes rgb = np.zeros(data.shape + (3,), dtype=data.dtype) rgb[r0[1]::2, r0[0]::2, 0] = data[r0[1]::2, r0[0]::2] # Red @@ -39,17 +28,9 @@ def separate_components(data, r0, g0, g1, b0): rgb[g1[1]::2, g1[0]::2, 1] = data[g1[1]::2, g1[0]::2] # Green rgb[b0[1]::2, b0[0]::2, 2] = data[b0[1]::2, b0[0]::2] # Blue - return rgb - - -def demosaic(rgb, r0, g0, g1, b0): - # At this point we now have the raw Bayer data with the correct values - # and colors but the data still requires de-mosaicing and - # post-processing. If you wish to do this yourself, end the script here! - # # Below we present a fairly naive de-mosaic method that simply # calculates the weighted average of a pixel based on the pixels - # surrounding it. The weighting is provided b0[1] a b0[1]te representation of + # surrounding it. The weighting is provided by a byte representation of # the Bayer filter which we construct first: bayer = np.zeros(rgb.shape, dtype=np.uint8) @@ -69,29 +50,6 @@ def demosaic(rgb, r0, g0, g1, b0): borders = (window[0] - 1, window[1] - 1) border = (borders[0] // 2, borders[1] // 2) - # rgb_pad = np.zeros(( - # rgb.shape[0] + borders[0], - # rgb.shape[1] + borders[1], - # rgb.shape[2]), dtype=rgb.dtype) - # rgb_pad[ - # border[0]:rgb_pad.shape[0] - border[0], - # border[1]:rgb_pad.shape[1] - border[1], - # :] = rgb - # rgb = rgb_pad - # - # bayer_pad = np.zeros(( - # bayer.shape[0] + borders[0], - # bayer.shape[1] + borders[1], - # bayer.shape[2]), dtype=bayer.dtype) - # bayer_pad[ - # border[0]:bayer_pad.shape[0] - border[0], - # border[1]:bayer_pad.shape[1] - border[1], - # :] = bayer - # bayer = bayer_pad - - # In numpy >=1.7.0 just use np.pad (version in Raspbian is 1.6.2 at the - # time of writing...) - # rgb = np.pad(rgb, [ (border[0], border[0]), (border[1], border[1]), @@ -168,7 +126,7 @@ def to_rgb(fmt, size, data): bayer_pattern = fmt[1:5] bitspp = int(fmt[5:]) - # TODO: shifting leaves the lowest bits 0 + # \todo shifting leaves the lowest bits 0 if bitspp == 8: data = data.reshape((h, w)) data = data.astype(np.uint16) << 8 @@ -195,8 +153,7 @@ def to_rgb(fmt, size, data): assert(idx != -1) b0 = (idx % 2, idx // 2) - rgb = separate_components(data, r0, g0, g1, b0) - rgb = demosaic(rgb, r0, g0, g1, b0) + rgb = demosaic(data, r0, g0, g1, b0) rgb = (rgb >> 8).astype(np.uint8) else: @@ -205,6 +162,13 @@ def to_rgb(fmt, size, data): return rgb +# A naive format conversion to 24-bit RGB +def mfb_to_rgb(mfb, cfg): + data = np.array(mfb.planes[0], dtype=np.uint8) + rgb = to_rgb(cfg.pixel_format, cfg.size, data) + return rgb + + class QtRenderer: def __init__(self, state): self.state = state @@ -334,9 +298,7 @@ class MainWindow(QtWidgets.QWidget): qim = ImageQt(img).copy() pix = QtGui.QPixmap.fromImage(qim) else: - data = np.array(mfb.planes[0], dtype=np.uint8) - rgb = to_rgb(cfg.pixel_format, cfg.size, data) - + rgb = mfb_to_rgb(mfb, cfg) if rgb is None: raise Exception('Format not supported: ' + cfg.pixel_format) From patchwork Wed May 18 13:13:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 15962 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 12159C3256 for ; Wed, 18 May 2022 13:14:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A204565669; Wed, 18 May 2022 15:14:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1652879646; bh=gn2amU8VE4PLh6T2oRe1CaqN5cONffQhEBi3RTvwtYI=; 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=g929QuppXhrWNVvzDa0PUOOn9mkepp1N3PgnbqoHmm82OU1xJGdTkcvbG+owf0oqp zvVk/jcf0IMjyDSvQMJInvZG5Xv/PumdHnK2NR+m0/K2sR7oN7bJGAHjwLY+RhZoc6 pIAVCNvoU+ONMvEycK1Q4K53n6f9KSwcHQkx8zoSIoe454ZfgTMQ/Qhr7xG/mrvTBA G7QDIBOY5nv9eWAng6+i1a8wLsGcBTy1EDIEmKp8pzdLpwOSeLBWZW07yZVZZJeyuc SivvKfG64IT2aQEJBvem03R0ct0s7FONnlxzlW/eGXxPD1qcK0nZHS0D/mwZpdTgX7 nkbjyHUxa/OIA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 962F765659 for ; Wed, 18 May 2022 15:13:52 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="tqJei5gu"; 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 F259F22BA; Wed, 18 May 2022 15:13:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1652879632; bh=gn2amU8VE4PLh6T2oRe1CaqN5cONffQhEBi3RTvwtYI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tqJei5guMG+oN+yR1Ez/Y0iFevD7Jpqc5ZWvJDXISq4hAojjvQx6q/P+CHtm8TAZn GmMvmmyiMVN0TmqtYPrwpsiuRlyCIWQbnCRynnVgaGhEnbBeDdSnOMB0+kQBPPPhTZ 93ccTP7KDNkl6TPeff8rrn44wCaHrwfIER577rGM= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Wed, 18 May 2022 16:13:23 +0300 Message-Id: <20220518131329.66994-13-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> References: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 12/18] py: implement PixelFormat class 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" Implement PixelFormat bindings properly with a PixelFormat class. Change the bindings to use the new class instead of a string. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/py/cam/cam.py | 2 +- src/py/cam/cam_kms.py | 10 +-------- src/py/cam/cam_qt.py | 4 +++- src/py/cam/cam_qtgl.py | 17 +-------------- src/py/cam/gl_helpers.py | 8 ------- src/py/libcamera/pymain.cpp | 42 ++++++++++++++++++------------------- 6 files changed, 27 insertions(+), 56 deletions(-) diff --git a/src/py/cam/cam.py b/src/py/cam/cam.py index c7da97d7..001fb9de 100755 --- a/src/py/cam/cam.py +++ b/src/py/cam/cam.py @@ -164,7 +164,7 @@ def configure(ctx): stream_config.size = (stream_opts['width'], stream_opts['height']) if 'pixelformat' in stream_opts: - stream_config.pixel_format = stream_opts['pixelformat'] + stream_config.pixel_format = libcam.PixelFormat(stream_opts['pixelformat']) stat = camconfig.validate() diff --git a/src/py/cam/cam_kms.py b/src/py/cam/cam_kms.py index d8ff0284..04381da1 100644 --- a/src/py/cam/cam_kms.py +++ b/src/py/cam/cam_kms.py @@ -5,14 +5,6 @@ import pykms import selectors import sys -FMT_MAP = { - 'RGB888': pykms.PixelFormat.RGB888, - 'YUYV': pykms.PixelFormat.YUYV, - 'ARGB8888': pykms.PixelFormat.ARGB8888, - 'XRGB8888': pykms.PixelFormat.XRGB8888, - 'NV12': pykms.PixelFormat.NV12, -} - class KMSRenderer: def __init__(self, state): @@ -120,7 +112,7 @@ class KMSRenderer: cfg = stream.configuration fmt = cfg.pixel_format - fmt = FMT_MAP[fmt] + fmt = pykms.PixelFormat(fmt.fourcc) plane = self.resman.reserve_generic_plane(self.crtc, fmt) assert(plane is not None) diff --git a/src/py/cam/cam_qt.py b/src/py/cam/cam_qt.py index fb485b9b..45a30aeb 100644 --- a/src/py/cam/cam_qt.py +++ b/src/py/cam/cam_qt.py @@ -87,6 +87,8 @@ def to_rgb(fmt, size, data): w = size[0] h = size[1] + fmt = str(fmt) + if fmt == 'YUYV': # YUV422 yuyv = data.reshape((h, w // 2 * 4)) @@ -293,7 +295,7 @@ class MainWindow(QtWidgets.QWidget): w, h = cfg.size pitch = cfg.stride - if cfg.pixel_format == 'MJPEG': + if str(cfg.pixel_format) == 'MJPEG': img = Image.open(BytesIO(mfb.planes[0])) qim = ImageQt(img).copy() pix = QtGui.QPixmap.fromImage(qim) diff --git a/src/py/cam/cam_qtgl.py b/src/py/cam/cam_qtgl.py index 8a95994e..261accb8 100644 --- a/src/py/cam/cam_qtgl.py +++ b/src/py/cam/cam_qtgl.py @@ -30,14 +30,6 @@ from OpenGL.GL import shaders from gl_helpers import * -# libcamera format string -> DRM fourcc -FMT_MAP = { - 'RGB888': 'RG24', - 'XRGB8888': 'XR24', - 'ARGB8888': 'AR24', - 'YUYV': 'YUYV', -} - class EglState: def __init__(self): @@ -204,12 +196,6 @@ class MainWindow(QtWidgets.QWidget): self.current[ctx['idx']] = [] for stream in ctx['streams']: - fmt = stream.configuration.pixel_format - size = stream.configuration.size - - if fmt not in FMT_MAP: - raise Exception('Unsupported pixel format: ' + str(fmt)) - self.textures[stream] = None num_tiles = len(self.textures) @@ -281,8 +267,7 @@ class MainWindow(QtWidgets.QWidget): def create_texture(self, stream, fb): cfg = stream.configuration - fmt = cfg.pixel_format - fmt = str_to_fourcc(FMT_MAP[fmt]) + fmt = cfg.pixel_format.fourcc w, h = cfg.size attribs = [ diff --git a/src/py/cam/gl_helpers.py b/src/py/cam/gl_helpers.py index ac5e6889..53b3e9df 100644 --- a/src/py/cam/gl_helpers.py +++ b/src/py/cam/gl_helpers.py @@ -30,14 +30,6 @@ def getglEGLImageTargetTexture2DOES(): glEGLImageTargetTexture2DOES = getglEGLImageTargetTexture2DOES() -# \todo This can be dropped when we have proper PixelFormat bindings -def str_to_fourcc(str): - assert(len(str) == 4) - fourcc = 0 - for i, v in enumerate([ord(c) for c in str]): - fourcc |= v << (i * 8) - return fourcc - def get_gl_extensions(): n = GLint() diff --git a/src/py/libcamera/pymain.cpp b/src/py/libcamera/pymain.cpp index af22205e..97b05903 100644 --- a/src/py/libcamera/pymain.cpp +++ b/src/py/libcamera/pymain.cpp @@ -8,7 +8,6 @@ /* * \todo Add geometry classes (Point, Rectangle...) * \todo Add bindings for the ControlInfo class - * \todo Add bindings for the PixelFormat class */ #include @@ -173,6 +172,7 @@ PYBIND11_MODULE(_libcamera, m) auto pyColorSpaceTransferFunction = py::enum_(pyColorSpace, "TransferFunction"); auto pyColorSpaceYcbcrEncoding = py::enum_(pyColorSpace, "YcbcrEncoding"); auto pyColorSpaceRange = py::enum_(pyColorSpace, "Range"); + auto pyPixelFormat = py::class_(m, "PixelFormat"); /* Global functions */ m.def("log_set_level", &logSetLevel); @@ -404,14 +404,7 @@ PYBIND11_MODULE(_libcamera, m) self.size.width = std::get<0>(size); self.size.height = std::get<1>(size); }) - .def_property( - "pixel_format", - [](StreamConfiguration &self) { - return self.pixelFormat.toString(); - }, - [](StreamConfiguration &self, std::string fmt) { - self.pixelFormat = PixelFormat::fromString(fmt); - }) + .def_readwrite("pixel_format", &StreamConfiguration::pixelFormat) .def_readwrite("stride", &StreamConfiguration::stride) .def_readwrite("frame_size", &StreamConfiguration::frameSize) .def_readwrite("buffer_count", &StreamConfiguration::bufferCount) @@ -420,22 +413,15 @@ PYBIND11_MODULE(_libcamera, m) .def_readwrite("color_space", &StreamConfiguration::colorSpace); pyStreamFormats - .def_property_readonly("pixel_formats", [](StreamFormats &self) { - std::vector fmts; - for (auto &fmt : self.pixelformats()) - fmts.push_back(fmt.toString()); - return fmts; - }) - .def("sizes", [](StreamFormats &self, const std::string &pixelFormat) { - auto fmt = PixelFormat::fromString(pixelFormat); + .def_property_readonly("pixel_formats", &StreamFormats::pixelformats) + .def("sizes", [](StreamFormats &self, const PixelFormat &pixelFormat) { std::vector> fmts; - for (const auto &s : self.sizes(fmt)) + for (const auto &s : self.sizes(pixelFormat)) fmts.push_back(std::make_tuple(s.width, s.height)); return fmts; }) - .def("range", [](StreamFormats &self, const std::string &pixelFormat) { - auto fmt = PixelFormat::fromString(pixelFormat); - const auto &range = self.range(fmt); + .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)); @@ -648,4 +634,18 @@ PYBIND11_MODULE(_libcamera, m) pyColorSpaceRange .value("Full", ColorSpace::Range::Full) .value("Limited", ColorSpace::Range::Limited); + + pyPixelFormat + .def(py::init<>()) + .def(py::init()) + .def(py::init<>([](const std::string &str) { + return PixelFormat::fromString(str); + })) + .def_property_readonly("fourcc", &PixelFormat::fourcc) + .def_property_readonly("modifier", &PixelFormat::modifier) + .def(py::self == py::self) + .def("__str__", &PixelFormat::toString) + .def("__repr__", [](const PixelFormat &self) { + return "libcamera.PixelFormat('" + self.toString() + "')"; + }); } From patchwork Wed May 18 13:13:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 15963 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 BF8AAC3273 for ; Wed, 18 May 2022 13:14:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 64A356566C; Wed, 18 May 2022 15:14:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1652879647; bh=MhU6IDsQwk3pKZOa/dcDDc1W2tZ4vDaeC8qiHQcr6Sk=; 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=3zTcqZfJr36dpYJx0FjGovT+hXBS4eWNFG1kCeN5poC2IYJbDqfCevFGjvBgnecbh Wsx3h4FOaN8BWHV0Jv95kuhAYYFHE5GldN77DqruqURBTfZnUa8nVJNnyI3FUEMtdY Gwh2OB3gZKhAWjRkNjWlrBJyEOUoaH9TV4Ick+Dy9I5IOuhYlly7xZ+LxzJKzZi5ze 4ouFV1Fx1TNT9sg5iQ0+JBHZ37f3GjGLjOf2JYaNFlv8sJ63mYQXSTkjZI61e9Urso pdLQsicdHv9H6XDLYgsYQQfm9/jZdxFwguYrYbD1+G/Vz7V5qbvBuM5+f/oTHV7la5 KNZFMtwKuLU8A== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 14B0465666 for ; Wed, 18 May 2022 15:13:53 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="qgCxWc2h"; 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 876BF29BA; Wed, 18 May 2022 15:13:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1652879632; bh=MhU6IDsQwk3pKZOa/dcDDc1W2tZ4vDaeC8qiHQcr6Sk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qgCxWc2hBsFuhgP/09IB1Zf1F8MZVNWeC9MwV/MjCbF6gD3FB7VmgghkS2+jzwLfH LoiHpfwRIHQkWRFuBn4vpMhR2qga2KcApvnhYVYCOrvkXBcfAAZ4mDeluOxYmEscAa gE8285Kw5WPAa9e7tyrqtmk42Ne5e+I8AT3OQYV4= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Wed, 18 May 2022 16:13:24 +0300 Message-Id: <20220518131329.66994-14-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> References: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 13/18] 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 Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/py/libcamera/meson.build | 1 + src/py/libcamera/pygeometry.cpp | 119 ++++++++++++++++++++++++++++++++ src/py/libcamera/pymain.cpp | 2 + 3 files changed, 122 insertions(+) create mode 100644 src/py/libcamera/pygeometry.cpp diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build index 427716d7..de66bb48 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..d77de144 --- /dev/null +++ b/src/py/libcamera/pygeometry.cpp @@ -0,0 +1,119 @@ +/* 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_pygeometry(py::module &m) +{ + auto pyPoint = py::class_(m, "Point"); + auto pySize = py::class_(m, "Size"); + auto pySizeRange = py::class_(m, "SizeRange"); + auto pyRectangle = py::class_(m, "Rectangle"); + + pyPoint + .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 py::str("libcamera.Point({}, {})") + .format(self.x, self.y); + }); + + pySize + .def(py::init<>()) + .def(py::init()) + .def_readwrite("width", &Size::width) + .def_readwrite("height", &Size::height) + .def_property_readonly("is_null", &Size::isNull) + .def("align_down_to", &Size::alignDownTo) + .def("align_up_to", &Size::alignUpTo) + .def("bound_to", &Size::boundTo) + .def("expand_to", &Size::expandTo) + .def("grow_by", &Size::growBy) + .def("shrink_by", &Size::shrinkBy) + .def("aligned_up_to", &Size::alignedUpTo) + .def("aligned_up_to", &Size::alignedUpTo) + .def("bounded_to", &Size::boundedTo) + .def("expanded_to", &Size::expandedTo) + .def("grown_by", &Size::grownBy) + .def("shrunk_by", &Size::shrunkBy) + .def("bounded_to_aspect_ratio", &Size::boundedToAspectRatio) + .def("expanded_to_aspect_ratio", &Size::expandedToAspectRatio) + .def("centered_to", &Size::centeredTo) + .def(py::self == py::self) + .def(py::self < py::self) + .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 py::str("libcamera.Size({}, {})") + .format(self.width, self.height); + }); + + pySizeRange + .def(py::init<>()) + .def(py::init()) + .def(py::init()) + .def(py::init()) + .def_readwrite("min", &SizeRange::min) + .def_readwrite("max", &SizeRange::max) + .def_readwrite("hStep", &SizeRange::hStep) + .def_readwrite("vStep", &SizeRange::vStep) + .def("contains", &SizeRange::contains) + .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); + }); + + pyRectangle + .def(py::init<>()) + .def(py::init()) + .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("scale_by", &Rectangle::scaleBy) + .def("translate_by", &Rectangle::translateBy) + .def("bounded_to", &Rectangle::boundedTo) + .def("enclosed_in", &Rectangle::enclosedIn) + .def("scaled_by", &Rectangle::scaledBy) + .def("translated_by", &Rectangle::translatedBy) + .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 97b05903..96333ebc 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_pygeometry(py::module &m); PYBIND11_MODULE(_libcamera, m) { init_pyenums(m); init_pyenums_generated(m); + init_pygeometry(m); /* Forward declarations */ From patchwork Wed May 18 13:13:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 15964 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 82069C326C for ; Wed, 18 May 2022 13:14:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1C0716567C; Wed, 18 May 2022 15:14:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1652879648; bh=G+8n/1pEFurPhZQdtmvMaEp+ig2oS10Exqa4JPW881o=; 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=byr3gG4yR7qSFGlo7tgyidKOfL6YBGUYninokGh1pI3pjuJemqes1WP0FVd9m11uc M+hIl02/rwjLrqki+Y36pZlyPi9XEM95WYzxwPOLj3TruNHbdGS+BthmjGKOcAIB+6 u8MXuwPnNshjXz7dRQHSOmyOMBFxhexe9Mr0aFJUnGsBEuz/HIOTQ/m9FzSeBMAfJ9 KT137zIMIu76F5Yyif+NgZmvGdN068ZNdlPSZwt4CZ7u94MKZTQakUucX3kn/B3+Z1 LroGN9c1+1Zi2lOOJA+W56czHwiIaAEMyRqstA76L2fAME8vGmClAzqCM1OrDvGktG xKKocXKCBprEQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 942BE6565D for ; Wed, 18 May 2022 15:13:53 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="qNrlfcO/"; 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 0EE82221E; Wed, 18 May 2022 15:13:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1652879633; bh=G+8n/1pEFurPhZQdtmvMaEp+ig2oS10Exqa4JPW881o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qNrlfcO/PpFjuIKKoJYTZ+eZ+K+UnA+See+J835IilSI+RDMaKIspQ91eOnfL8gRm 4jRLa2c/ke3/TL92bmbOPlA6uqoat9HyHpvTDFPVOUjwtpiA2JMZO5JswlFKVmGYgN QlkfpN1/I6fObqb0g4ovyYUJruP5OZy8h1eYroHo= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Wed, 18 May 2022 16:13:25 +0300 Message-Id: <20220518131329.66994-15-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> References: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 14/18] 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 Reviewed-by: Kieran Bingham --- src/py/cam/cam.py | 7 +++++-- src/py/cam/cam_kms.py | 3 ++- src/py/cam/cam_qt.py | 7 ++++--- src/py/cam/cam_qtgl.py | 3 ++- src/py/libcamera/pymain.cpp | 41 ++++++++----------------------------- 5 files changed, 22 insertions(+), 39 deletions(-) diff --git a/src/py/cam/cam.py b/src/py/cam/cam.py index 001fb9de..2f0690b5 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(stream_opts['pixelformat']) diff --git a/src/py/cam/cam_kms.py b/src/py/cam/cam_kms.py index 04381da1..74cd3b38 100644 --- a/src/py/cam/cam_kms.py +++ b/src/py/cam/cam_kms.py @@ -126,7 +126,8 @@ class KMSRenderer: }) for fb in ctx['allocator'].buffers(stream): - w, h = cfg.size + w = cfg.size.width + h = cfg.size.height fds = [] strides = [] offsets = [] diff --git a/src/py/cam/cam_qt.py b/src/py/cam/cam_qt.py index 45a30aeb..91be2a08 100644 --- a/src/py/cam/cam_qt.py +++ b/src/py/cam/cam_qt.py @@ -84,8 +84,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 = str(fmt) @@ -292,7 +292,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 str(cfg.pixel_format) == '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 96333ebc..ef3f157a 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>()) From patchwork Wed May 18 13:13:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 15965 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 693E1C3274 for ; Wed, 18 May 2022 13:14:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F1A206567D; Wed, 18 May 2022 15:14:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1652879649; bh=ADJ4CtCHm4hVdF+HGnyBnjk6Sdw3ATPP2dpWo/YuFjU=; 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=GkwwlIVv6FRAn+FlUrBfZ9zKH9c+rmDp5Yhkctrt4mEkmw6l9wY1ow/qzXa9Ph84U YK/00R0tBiLAuiUZDu2fBOYf/7D/RnCUqKTHRrexHRxEXvdqi2QeZ/yDNJrd1UezCO 2SV2zlJgs7VtYH4nhj3fWNHDyQUmKrSAhyzJAZ5z+pOi/6y8kILc0hUP9HWqWjip8X 4cQyKTiXk0+RGnJwykD1cGjDOhSg376kMcGq7AbBzZCqNsv90sWQo04pV5Bg17bVYa yXz/kNCcbj8hJiVk8BBImmYvsUAmkkTo9gjWrjgoUhXNyMY/XkGpUMl9j7a2J+iJLk BuAX+tFNvOz1Q== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1F6A065675 for ; Wed, 18 May 2022 15:13:54 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="eVB6BNt4"; 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 8D4D82FE3; Wed, 18 May 2022 15:13:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1652879633; bh=ADJ4CtCHm4hVdF+HGnyBnjk6Sdw3ATPP2dpWo/YuFjU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eVB6BNt4ODx5ZitRdKyVgQAB1vyMZnJ6+mmeAcebsVu4gihDCRw75dGiZOEiKsvJm Grgyik+KQC37PhZVl3GXI0ae62U9Y/peNBPDd0kLlugJY6BFN0BeNzRI+ZqpzaCKck KDKccOHEUbuFl1B32mz7+TWaujELHTDF9yPjrmYI= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Wed, 18 May 2022 16:13:26 +0300 Message-Id: <20220518131329.66994-16-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> References: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 15/18] py: rename pyxyz to py_xyz 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" Having the underscore makes the names more readable, especially when there are multiple words in the name. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/py/libcamera/meson.build | 10 +++++----- src/py/libcamera/{pyenums.cpp => py_enums.cpp} | 2 +- ...ms_generated.cpp.in => py_enums_generated.cpp.in} | 2 +- src/py/libcamera/{pygeometry.cpp => py_geometry.cpp} | 2 +- src/py/libcamera/{pymain.cpp => py_main.cpp} | 12 ++++++------ 5 files changed, 14 insertions(+), 14 deletions(-) rename src/py/libcamera/{pyenums.cpp => py_enums.cpp} (96%) rename src/py/libcamera/{pyenums_generated.cpp.in => py_enums_generated.cpp.in} (89%) rename src/py/libcamera/{pygeometry.cpp => py_geometry.cpp} (99%) rename src/py/libcamera/{pymain.cpp => py_main.cpp} (99%) diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build index de66bb48..55957252 100644 --- a/src/py/libcamera/meson.build +++ b/src/py/libcamera/meson.build @@ -13,21 +13,21 @@ pybind11_proj = subproject('pybind11') pybind11_dep = pybind11_proj.get_variable('pybind11_dep') pycamera_sources = files([ - 'pyenums.cpp', - 'pygeometry.cpp', - 'pymain.cpp', + 'py_enums.cpp', + 'py_geometry.cpp', + 'py_main.cpp', ]) gen_input_files = files([ '../../libcamera/control_ids.yaml', - 'pyenums_generated.cpp.in', + 'py_enums_generated.cpp.in', ]) gen_py_control_enums = files('gen-py-control-enums.py') generated_sources = custom_target('py_gen_controls', input : gen_input_files, - output : ['pyenums_generated.cpp'], + output : ['py_enums_generated.cpp'], command : [gen_py_control_enums, '-o', '@OUTPUT@', '@INPUT@']) pycamera_sources += generated_sources diff --git a/src/py/libcamera/pyenums.cpp b/src/py/libcamera/py_enums.cpp similarity index 96% rename from src/py/libcamera/pyenums.cpp rename to src/py/libcamera/py_enums.cpp index b655e622..e55318f1 100644 --- a/src/py/libcamera/pyenums.cpp +++ b/src/py/libcamera/py_enums.cpp @@ -13,7 +13,7 @@ namespace py = pybind11; using namespace libcamera; -void init_pyenums(py::module &m) +void init_py_enums(py::module &m) { py::enum_(m, "StreamRole") .value("StillCapture", StreamRole::StillCapture) diff --git a/src/py/libcamera/pyenums_generated.cpp.in b/src/py/libcamera/py_enums_generated.cpp.in similarity index 89% rename from src/py/libcamera/pyenums_generated.cpp.in rename to src/py/libcamera/py_enums_generated.cpp.in index 6aaf4795..20e07528 100644 --- a/src/py/libcamera/pyenums_generated.cpp.in +++ b/src/py/libcamera/py_enums_generated.cpp.in @@ -15,7 +15,7 @@ namespace py = pybind11; using namespace libcamera; -void init_pyenums_generated(py::module& m) +void init_py_enums_generated(py::module& m) { ${enums} } diff --git a/src/py/libcamera/pygeometry.cpp b/src/py/libcamera/py_geometry.cpp similarity index 99% rename from src/py/libcamera/pygeometry.cpp rename to src/py/libcamera/py_geometry.cpp index d77de144..84b0cb08 100644 --- a/src/py/libcamera/pygeometry.cpp +++ b/src/py/libcamera/py_geometry.cpp @@ -18,7 +18,7 @@ namespace py = pybind11; using namespace libcamera; -void init_pygeometry(py::module &m) +void init_py_geometry(py::module &m) { auto pyPoint = py::class_(m, "Point"); auto pySize = py::class_(m, "Size"); diff --git a/src/py/libcamera/pymain.cpp b/src/py/libcamera/py_main.cpp similarity index 99% rename from src/py/libcamera/pymain.cpp rename to src/py/libcamera/py_main.cpp index ef3f157a..b05bbb22 100644 --- a/src/py/libcamera/pymain.cpp +++ b/src/py/libcamera/py_main.cpp @@ -130,15 +130,15 @@ static void handleRequestCompleted(Request *req) LOG(Fatal) << "Unable to write to eventfd"; } -void init_pyenums(py::module &m); -void init_pyenums_generated(py::module &m); -void init_pygeometry(py::module &m); +void init_py_enums(py::module &m); +void init_py_enums_generated(py::module &m); +void init_py_geometry(py::module &m); PYBIND11_MODULE(_libcamera, m) { - init_pyenums(m); - init_pyenums_generated(m); - init_pygeometry(m); + init_py_enums(m); + init_py_enums_generated(m); + init_py_geometry(m); /* Forward declarations */ From patchwork Wed May 18 13:13:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 15967 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 9DA2BC3275 for ; Wed, 18 May 2022 13:14:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0ED1865671; Wed, 18 May 2022 15:14:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1652879651; bh=BFl081IYvSgCzhZfDzo328VBEKwa3VfS1UaR2JghE1g=; 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=tyYkEtkLgLBzk9HbufPWtNA0bGF+RK7sdc4r7bL+d2f19ZMTwspotpdo0L7LpP7/X juJ+uDaC7sQb5Zp1MClHLZiAOHzlMUJfSYdMNEzhty4KQdML72SMp7Cu0ylzuAm0b8 /jh8km1HKEfSpwEDQSCDsQOrRoYzHHeCq3MBJO4SxiFe8QGItxfX/q3+i6ug5iZDbT nG3pWcT5RLrT33DGEBmZhNW/RUabfzZ5ppfdQbhJKXrefn/R8iBhYTiW6TF1P0ghSU reIR0VQ3AvdBurfBEUaqnIyCmeBBNIH6bCmFWxG2yOtKRpXbJGJA+Q9Bv3vDi33bLy vL1T+D7Sk0POQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9949B65678 for ; Wed, 18 May 2022 15:13:54 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="tRhFMcy6"; 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 1623D3297; Wed, 18 May 2022 15:13:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1652879634; bh=BFl081IYvSgCzhZfDzo328VBEKwa3VfS1UaR2JghE1g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tRhFMcy6y1WxlOaWdDZaA3pMmYV+1Nzn/m3ktW80JaUvOr6Q/jMOwID3h2FBj7fYi AhjGWdff9Pg2dEkBt3bx06X9Clf4gccXwOLGzdNju+NkcxtpHf8tlQ8SvbdwHPAYGV z+cIqeY2AEOoSbEbqLatcw2epwCll9ZR/qxdacsg= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Wed, 18 May 2022 16:13:27 +0300 Message-Id: <20220518131329.66994-17-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> References: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 16/18] py: clean up control enums generation 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" Try to be more consistent with the names, and include "control" in all the names. Also drop a useless "using namespace libcamera" and only include "control_ids.h". Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/py/libcamera/meson.build | 12 +++++------- ...ated.cpp.in => py_control_enums_generated.cpp.in} | 8 +++----- src/py/libcamera/py_main.cpp | 4 ++-- 3 files changed, 10 insertions(+), 14 deletions(-) rename src/py/libcamera/{py_enums_generated.cpp.in => py_control_enums_generated.cpp.in} (63%) diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build index 55957252..a3388c63 100644 --- a/src/py/libcamera/meson.build +++ b/src/py/libcamera/meson.build @@ -18,20 +18,18 @@ pycamera_sources = files([ 'py_main.cpp', ]) -gen_input_files = files([ +gen_py_control_enums_input_files = files([ '../../libcamera/control_ids.yaml', - 'py_enums_generated.cpp.in', + 'py_control_enums_generated.cpp.in', ]) gen_py_control_enums = files('gen-py-control-enums.py') -generated_sources = custom_target('py_gen_controls', - input : gen_input_files, - output : ['py_enums_generated.cpp'], +pycamera_sources += custom_target('py_gen_controls', + input : gen_py_control_enums_input_files, + output : ['py_control_enums_generated.cpp'], command : [gen_py_control_enums, '-o', '@OUTPUT@', '@INPUT@']) -pycamera_sources += generated_sources - pycamera_deps = [ libcamera_public, py3_dep, diff --git a/src/py/libcamera/py_enums_generated.cpp.in b/src/py/libcamera/py_control_enums_generated.cpp.in similarity index 63% rename from src/py/libcamera/py_enums_generated.cpp.in rename to src/py/libcamera/py_control_enums_generated.cpp.in index 20e07528..ed81fbe7 100644 --- a/src/py/libcamera/py_enums_generated.cpp.in +++ b/src/py/libcamera/py_control_enums_generated.cpp.in @@ -2,20 +2,18 @@ /* * Copyright (C) 2022, Tomi Valkeinen * - * Python bindings - Auto-generated enums + * Python bindings - Auto-generated control enums * * This file is auto-generated. Do not edit. */ -#include +#include #include namespace py = pybind11; -using namespace libcamera; - -void init_py_enums_generated(py::module& m) +void init_py_control_enums_generated(py::module& m) { ${enums} } diff --git a/src/py/libcamera/py_main.cpp b/src/py/libcamera/py_main.cpp index b05bbb22..1d941160 100644 --- a/src/py/libcamera/py_main.cpp +++ b/src/py/libcamera/py_main.cpp @@ -131,13 +131,13 @@ static void handleRequestCompleted(Request *req) } void init_py_enums(py::module &m); -void init_py_enums_generated(py::module &m); +void init_py_control_enums_generated(py::module &m); void init_py_geometry(py::module &m); PYBIND11_MODULE(_libcamera, m) { init_py_enums(m); - init_py_enums_generated(m); + init_py_control_enums_generated(m); init_py_geometry(m); /* Forward declarations */ From patchwork Wed May 18 13:13:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 15966 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 6E9F0C326D for ; Wed, 18 May 2022 13:14:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0C31F65670; Wed, 18 May 2022 15:14:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1652879650; bh=POBN2UUasnTVP4s+8csr4u5zfcA7NuEJONAMXGjgQaU=; 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=nCTXyG4HdE1OfKahNCV6FaKD6oocFKEZNeEEx8xlSeeM5AX5W/qd3MS5ZPFG1LBYf eBhffMq1V7xRg1gBhYtJR8jG9F5hCn3+LxReZgDiGrd+9pvLUJiX/LzaCaujTR3ASY JeNWKD6wevk5w0M60BwNLV9A/FadSxnWP1kDgtA+GmZEOJMaFJtg3rENKhGjJKM1Ko w5uxgwBPhfU78DXMzFUOo/sexr9aagR49JyxXEzNyZMJUm81/ixvxNEYJTYVB5OVLE dy84aWptlnc4w25x5uIeyz2LzwjEfm8Yf/I1FcHvNiMWYrv8J4HeLDXVPtP4kvfsc5 O1MFJeH7IZNTw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2EDB265679 for ; Wed, 18 May 2022 15:13:55 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="UmiaYJ52"; 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 937EB1AAA; Wed, 18 May 2022 15:13:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1652879634; bh=POBN2UUasnTVP4s+8csr4u5zfcA7NuEJONAMXGjgQaU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UmiaYJ529ybqxetpzjvKok3Y4qAlaZKBn3nknvqht/DZxq3NaCsoqSNHW37o5sp+E 29HhYHYBIzWFEC6iqjKscP9//Sl3K8/PlcnQbQxil6eAxRx7OnifwqIiJrlC4lcOj+ k/gmAWLmxFg1p1CtoiUq3mIIxzqX+RjFZhbynY9s= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Wed, 18 May 2022 16:13:28 +0300 Message-Id: <20220518131329.66994-18-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> References: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 17/18] py: generate pixel formats list 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" Generate a list of pixel formats under "libcamera.formats". I'm not super happy about this solution, as the user can change the formats (libcamera.formats.XRGB8888 = None) and, for some reason, pybind11-stubgen doesn't produce stubs for this. However, other than the two issues above, it works, and I haven't figured out a better way. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/py/libcamera/gen-py-formats.py | 56 ++++++++++++++++++++ src/py/libcamera/meson.build | 12 +++++ src/py/libcamera/py_formats_generated.cpp.in | 21 ++++++++ src/py/libcamera/py_main.cpp | 3 ++ 4 files changed, 92 insertions(+) create mode 100755 src/py/libcamera/gen-py-formats.py create mode 100644 src/py/libcamera/py_formats_generated.cpp.in diff --git a/src/py/libcamera/gen-py-formats.py b/src/py/libcamera/gen-py-formats.py new file mode 100755 index 00000000..72565a25 --- /dev/null +++ b/src/py/libcamera/gen-py-formats.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Generate Python format definitions from YAML + +import argparse +import string +import sys +import yaml + + +def generate(formats): + fmts = [] + + for format in formats: + name, format = format.popitem() + fmts.append(f'formats.attr("{name}") = &libcamera::formats::{name};') + + return {'formats': '\n'.join(fmts)} + + +def fill_template(template, data): + with open(template, encoding='utf-8') as f: + template = f.read() + + template = string.Template(template) + return template.substitute(data) + + +def main(argv): + parser = argparse.ArgumentParser() + parser.add_argument('-o', dest='output', metavar='file', type=str, + help='Output file name. Defaults to standard output if not specified.') + parser.add_argument('input', type=str, + help='Input file name.') + parser.add_argument('template', type=str, + help='Template file name.') + args = parser.parse_args(argv[1:]) + + with open(args.input, encoding='utf-8') as f: + formats = yaml.safe_load(f)['formats'] + + data = generate(formats) + data = fill_template(args.template, data) + + if args.output: + with open(args.output, 'w', encoding='utf-8') as f: + f.write(data) + else: + sys.stdout.write(data) + + return 0 + + +if __name__ == '__main__': + sys.exit(main(sys.argv)) diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build index a3388c63..0a7b65f3 100644 --- a/src/py/libcamera/meson.build +++ b/src/py/libcamera/meson.build @@ -30,6 +30,18 @@ pycamera_sources += custom_target('py_gen_controls', output : ['py_control_enums_generated.cpp'], command : [gen_py_control_enums, '-o', '@OUTPUT@', '@INPUT@']) +gen_py_formats_input_files = files([ + '../../libcamera/formats.yaml', + 'py_formats_generated.cpp.in', +]) + +gen_py_formats = files('gen-py-formats.py') + +pycamera_sources += custom_target('py_gen_formats', + input : gen_py_formats_input_files, + output : ['py_formats_generated.cpp'], + command : [gen_py_formats, '-o', '@OUTPUT@', '@INPUT@']) + pycamera_deps = [ libcamera_public, py3_dep, diff --git a/src/py/libcamera/py_formats_generated.cpp.in b/src/py/libcamera/py_formats_generated.cpp.in new file mode 100644 index 00000000..1100c024 --- /dev/null +++ b/src/py/libcamera/py_formats_generated.cpp.in @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Tomi Valkeinen + * + * Python bindings - Auto-generated formats + * + * This file is auto-generated. Do not edit. + */ + +#include + +#include + +namespace py = pybind11; + +void init_py_formats_generated(py::module& m) +{ +auto formats = m.def_submodule("formats"); + +${formats} +} diff --git a/src/py/libcamera/py_main.cpp b/src/py/libcamera/py_main.cpp index 1d941160..e7066841 100644 --- a/src/py/libcamera/py_main.cpp +++ b/src/py/libcamera/py_main.cpp @@ -132,6 +132,7 @@ static void handleRequestCompleted(Request *req) void init_py_enums(py::module &m); void init_py_control_enums_generated(py::module &m); +void init_py_formats_generated(py::module &m); void init_py_geometry(py::module &m); PYBIND11_MODULE(_libcamera, m) @@ -171,6 +172,8 @@ PYBIND11_MODULE(_libcamera, m) auto pyColorSpaceRange = py::enum_(pyColorSpace, "Range"); auto pyPixelFormat = py::class_(m, "PixelFormat"); + init_py_formats_generated(m); + /* Global functions */ m.def("log_set_level", &logSetLevel); From patchwork Wed May 18 13:13:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 15968 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 4D826C3276 for ; Wed, 18 May 2022 13:14:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D36F465681; Wed, 18 May 2022 15:14:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1652879651; bh=Q25Ba4mjLxmvzDleDRORF9gDsRZxtS6O/odB5NQekI4=; 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=unMtBjAUPUjs6CcP66DUPoeLfmFfVkU3se6cZLaedPnHsyNKd/14uBJVj9WDYPkHE 3DcpAb2PTSc6j85zplsxGWivM89WE7LYFHA8f7vLIiNLvlSRF72zT7xQUsb+6ewjZo 9N4kE7kLPvqxSwOKEm3vm5NWi7Pr/1VIQvYGrvOrGab220yDF8sgXZS1y9zkeQQzzi GhrJxfecXu6uzEPdPlIwXXzoEWPfoXbVuSkIkvfstj5LN2PVTRKWy24nUwueAf+cpk 66PLdu21/s+6XODC9YVZJwI/y2laFE/7gb2iRTwtp52dzp6Z10+Mo+6TKVnw80+GkE FkFV9DNx5BHVQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9F0336565E for ; Wed, 18 May 2022 15:13:55 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="aHlkCN6G"; 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 1B9561BBB; Wed, 18 May 2022 15:13:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1652879635; bh=Q25Ba4mjLxmvzDleDRORF9gDsRZxtS6O/odB5NQekI4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aHlkCN6GWBj5nBEGydA4AjeerLetKbEJIKRhQbl2B7rhoGqe1JcobIrk0lR5ceAHb KvzRHB3nXBGPS0DUNpLmswBjiNySp18Jn2l0HJwpdZJy10G4ge+m3nytBLIrqW1+lN ini6cHlSYFHsTyn2a6PloxBAsWO2kBRld3u74yhU= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Wed, 18 May 2022 16:13:29 +0300 Message-Id: <20220518131329.66994-19-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> References: <20220518131329.66994-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 18/18] py: cam_qt: use libcamera.formats 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" Use the new libcamera.formats in cam_qt.py. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/py/cam/cam_qt.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/py/cam/cam_qt.py b/src/py/cam/cam_qt.py index 91be2a08..142bb35e 100644 --- a/src/py/cam/cam_qt.py +++ b/src/py/cam/cam_qt.py @@ -8,6 +8,7 @@ from numpy.lib.stride_tricks import as_strided from PIL import Image from PIL.ImageQt import ImageQt from PyQt5 import QtCore, QtGui, QtWidgets +import libcamera as libcam import numpy as np import sys @@ -87,9 +88,7 @@ def to_rgb(fmt, size, data): w = size.width h = size.height - fmt = str(fmt) - - if fmt == 'YUYV': + if fmt == libcam.formats.YUYV: # YUV422 yuyv = data.reshape((h, w // 2 * 4)) @@ -111,20 +110,22 @@ def to_rgb(fmt, size, data): rgb[:, :, 2] -= 226.8183044444304 rgb = rgb.astype(np.uint8) - elif fmt == 'RGB888': + elif fmt == libcam.formats.RGB888: rgb = data.reshape((h, w, 3)) rgb[:, :, [0, 1, 2]] = rgb[:, :, [2, 1, 0]] - elif fmt == 'BGR888': + elif fmt == libcam.formats.BGR888: rgb = data.reshape((h, w, 3)) - elif fmt in ['ARGB8888', 'XRGB8888']: + elif fmt in [libcam.formats.ARGB8888, libcam.formats.XRGB8888]: rgb = data.reshape((h, w, 4)) rgb = np.flip(rgb, axis=2) # drop alpha component rgb = np.delete(rgb, np.s_[0::4], axis=2) - elif fmt.startswith('S'): + elif str(fmt).startswith('S'): + # \todo implement PixelFormatInfo and use it here + fmt = str(fmt) bayer_pattern = fmt[1:5] bitspp = int(fmt[5:]) @@ -296,7 +297,7 @@ class MainWindow(QtWidgets.QWidget): h = cfg.size.height pitch = cfg.stride - if str(cfg.pixel_format) == 'MJPEG': + if cfg.pixel_format == libcam.formats.MJPEG: img = Image.open(BytesIO(mfb.planes[0])) qim = ImageQt(img).copy() pix = QtGui.QPixmap.fromImage(qim)