From patchwork Fri May 27 14:44: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: 16081 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 34E14C3256 for ; Fri, 27 May 2022 14:45:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AD5D76569B; Fri, 27 May 2022 16:45:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1653662721; bh=xjZDfH58LT4jSfynEsxb2kPyIgf1vbSIf/kjeuwUJB4=; 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=q1I9zsiyHW90dBoPOCUS/XEu7C1V/hn3cKyMDAltDT2V+RKKJ6SquAFghqXPYrqjK IYknmmo70pjnMUFVFLkNN9RinzJpZahBMQiyDu71Xbrr3a1K/KbBVyHMcDynV3BkBJ p0tLiEs79XOdK48aavelDvNp8Eh3PN5VUUR0CJ7hyZDmJBJ0vJi9TYYWN7p4kShNGp xoMhlCcbDUGpXVJb2yPRdU+ZdDQWG6wnTWVJYd64c/jDBq3NmMQezGsEu89mvBwDWt gu3wU2l/2KFPphKbgg4Oa+2A5D+JgIPvcStDR7V+S6fvFf6hrKeHyoTQp6xER60kRE rSwsmijZTyvbg== 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 B1D3465641 for ; Fri, 27 May 2022 16:45:10 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="SxStX9KD"; 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 2E7A9A58; Fri, 27 May 2022 16:45:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1653662710; bh=xjZDfH58LT4jSfynEsxb2kPyIgf1vbSIf/kjeuwUJB4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SxStX9KDNKfDXdXwYWlxv7Y6/S+e/ETyPyD8FnpY4aQDLAj6nwXY6TGcBiSZO3m7c N3apYhfuDkAxHu9S0Wk/6fqWBfg+fHOUJcMAxEec3PO9TezikqBZlveFTBZmgBAKPX TXq5aHY9BBRTed4iq9KY2K6WlKC+iRdn4HqgF4aM= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Fri, 27 May 2022 17:44:29 +0300 Message-Id: <20220527144447.94891-13-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220527144447.94891-1-tomi.valkeinen@ideasonboard.com> References: <20220527144447.94891-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 12/30] py: Re-implement controls geneneration 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" The Python bindings controls generation was not very good. It only covered the enums and they were in the main namespace. This adds the controls somewhat similarly to the C++ side. We will have e.g.: libcamera.controls.Brightness libcamera.controls.AeMeteringModeEnum.CentreWeighted Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart --- ...py-control-enums.py => gen-py-controls.py} | 20 +++++++++++-------- src/py/libcamera/meson.build | 16 +++++++++------ ...ed.cpp.in => py_controls_generated.cpp.in} | 17 +++++++++++++--- src/py/libcamera/py_main.cpp | 4 ++-- 4 files changed, 38 insertions(+), 19 deletions(-) rename src/py/libcamera/{gen-py-control-enums.py => gen-py-controls.py} (85%) rename src/py/libcamera/{py_control_enums_generated.cpp.in => py_controls_generated.cpp.in} (50%) diff --git a/src/py/libcamera/gen-py-control-enums.py b/src/py/libcamera/gen-py-controls.py similarity index 85% rename from src/py/libcamera/gen-py-control-enums.py rename to src/py/libcamera/gen-py-controls.py index 6b2b5362..4c072e60 100755 --- a/src/py/libcamera/gen-py-control-enums.py +++ b/src/py/libcamera/gen-py-controls.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0-or-later # -# Generate Python bindings enums for controls from YAML +# Generate Python bindings controls from YAML import argparse import string @@ -27,18 +27,22 @@ def generate_py(controls): for ctrl in controls: name, ctrl = ctrl.popitem() - enum = ctrl.get('enum') - if not enum: - continue - if ctrl.get('draft'): ns = 'libcamera::controls::draft::' + container = 'draft' else: ns = 'libcamera::controls::' + container = 'controls' + + out += f'\t{container}.def_readonly_static("{name}", static_cast(&{ns}{name}));\n\n' + + enum = ctrl.get('enum') + if not enum: + continue cpp_enum = name + 'Enum' - out += '\tpy::enum_<{}{}>(m, \"{}\")\n'.format(ns, cpp_enum, name) + out += '\tpy::enum_<{}{}>({}, \"{}\")\n'.format(ns, cpp_enum, container, cpp_enum) if name == 'LensShadingMapMode': prefix = 'LensShadingMapMode' @@ -54,9 +58,9 @@ def generate_py(controls): out += '\t\t.value(\"{}\", {}{})\n'.format(py_enum, ns, cpp_enum) - out += '\t;\n' + out += '\t;\n\n' - return {'enums': out} + return {'controls': out} def fill_template(template, data): diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build index b705ac1f..e8010846 100644 --- a/src/py/libcamera/meson.build +++ b/src/py/libcamera/meson.build @@ -18,17 +18,21 @@ pycamera_sources = files([ 'py_main.cpp', ]) -gen_py_control_enums_input_files = files([ +# Generate controls + +gen_py_controls_input_files = files([ '../../libcamera/control_ids.yaml', - 'py_control_enums_generated.cpp.in', + 'py_controls_generated.cpp.in', ]) -gen_py_control_enums = files('gen-py-control-enums.py') +gen_py_controls = files('gen-py-controls.py') 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@']) + input : gen_py_controls_input_files, + output : ['py_controls_generated.cpp'], + command : [gen_py_controls, '-o', '@OUTPUT@', '@INPUT@']) + +# Generate formats gen_py_formats_input_files = files([ '../../libcamera/formats.yaml', diff --git a/src/py/libcamera/py_control_enums_generated.cpp.in b/src/py/libcamera/py_controls_generated.cpp.in similarity index 50% rename from src/py/libcamera/py_control_enums_generated.cpp.in rename to src/py/libcamera/py_controls_generated.cpp.in index ed81fbe7..cb8442ba 100644 --- a/src/py/libcamera/py_control_enums_generated.cpp.in +++ b/src/py/libcamera/py_controls_generated.cpp.in @@ -2,7 +2,7 @@ /* * Copyright (C) 2022, Tomi Valkeinen * - * Python bindings - Auto-generated control enums + * Python bindings - Auto-generated controls * * This file is auto-generated. Do not edit. */ @@ -13,7 +13,18 @@ namespace py = pybind11; -void init_py_control_enums_generated(py::module& m) +class PyControls { -${enums} +}; + +class PyDraftControls +{ +}; + +void init_py_controls_generated(py::module& m) +{ + auto controls = py::class_(m, "controls"); + auto draft = py::class_(controls, "draft"); + +${controls} } diff --git a/src/py/libcamera/py_main.cpp b/src/py/libcamera/py_main.cpp index 5d389942..33ecc1cd 100644 --- a/src/py/libcamera/py_main.cpp +++ b/src/py/libcamera/py_main.cpp @@ -131,14 +131,14 @@ static void handleRequestCompleted(Request *req) } void init_py_enums(py::module &m); -void init_py_control_enums_generated(py::module &m); +void init_py_controls_generated(py::module &m); void init_py_formats_generated(py::module &m); void init_py_geometry(py::module &m); PYBIND11_MODULE(_libcamera, m) { init_py_enums(m); - init_py_control_enums_generated(m); + init_py_controls_generated(m); init_py_geometry(m); /* Forward declarations */