py: Re-implement controls geneneration
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 <tomi.valkeinen@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
parent
6eb1143e27
commit
3c82ae3821
4 changed files with 39 additions and 20 deletions
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
# 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 argparse
|
||||||
import string
|
import string
|
||||||
|
@ -27,18 +27,22 @@ def generate_py(controls):
|
||||||
for ctrl in controls:
|
for ctrl in controls:
|
||||||
name, ctrl = ctrl.popitem()
|
name, ctrl = ctrl.popitem()
|
||||||
|
|
||||||
|
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<const libcamera::ControlId *>(&{ns}{name}));\n\n'
|
||||||
|
|
||||||
enum = ctrl.get('enum')
|
enum = ctrl.get('enum')
|
||||||
if not enum:
|
if not enum:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if ctrl.get('draft'):
|
|
||||||
ns = 'libcamera::controls::draft::'
|
|
||||||
else:
|
|
||||||
ns = 'libcamera::controls::'
|
|
||||||
|
|
||||||
cpp_enum = name + 'Enum'
|
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':
|
if name == 'LensShadingMapMode':
|
||||||
prefix = 'LensShadingMapMode'
|
prefix = 'LensShadingMapMode'
|
||||||
|
@ -54,9 +58,9 @@ def generate_py(controls):
|
||||||
|
|
||||||
out += '\t\t.value(\"{}\", {}{})\n'.format(py_enum, ns, cpp_enum)
|
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):
|
def fill_template(template, data):
|
|
@ -18,17 +18,21 @@ pycamera_sources = files([
|
||||||
'py_main.cpp',
|
'py_main.cpp',
|
||||||
])
|
])
|
||||||
|
|
||||||
gen_py_control_enums_input_files = files([
|
# Generate controls
|
||||||
|
|
||||||
|
gen_py_controls_input_files = files([
|
||||||
'../../libcamera/control_ids.yaml',
|
'../../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',
|
pycamera_sources += custom_target('py_gen_controls',
|
||||||
input : gen_py_control_enums_input_files,
|
input : gen_py_controls_input_files,
|
||||||
output : ['py_control_enums_generated.cpp'],
|
output : ['py_controls_generated.cpp'],
|
||||||
command : [gen_py_control_enums, '-o', '@OUTPUT@', '@INPUT@'])
|
command : [gen_py_controls, '-o', '@OUTPUT@', '@INPUT@'])
|
||||||
|
|
||||||
|
# Generate formats
|
||||||
|
|
||||||
gen_py_formats_input_files = files([
|
gen_py_formats_input_files = files([
|
||||||
'../../libcamera/formats.yaml',
|
'../../libcamera/formats.yaml',
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2022, Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
|
* Copyright (C) 2022, Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
|
||||||
*
|
*
|
||||||
* Python bindings - Auto-generated control enums
|
* Python bindings - Auto-generated controls
|
||||||
*
|
*
|
||||||
* This file is auto-generated. Do not edit.
|
* This file is auto-generated. Do not edit.
|
||||||
*/
|
*/
|
||||||
|
@ -13,7 +13,18 @@
|
||||||
|
|
||||||
namespace py = pybind11;
|
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_<PyControls>(m, "controls");
|
||||||
|
auto draft = py::class_<PyDraftControls>(controls, "draft");
|
||||||
|
|
||||||
|
${controls}
|
||||||
}
|
}
|
|
@ -131,14 +131,14 @@ static void handleRequestCompleted(Request *req)
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_py_enums(py::module &m);
|
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_formats_generated(py::module &m);
|
||||||
void init_py_geometry(py::module &m);
|
void init_py_geometry(py::module &m);
|
||||||
|
|
||||||
PYBIND11_MODULE(_libcamera, m)
|
PYBIND11_MODULE(_libcamera, m)
|
||||||
{
|
{
|
||||||
init_py_enums(m);
|
init_py_enums(m);
|
||||||
init_py_control_enums_generated(m);
|
init_py_controls_generated(m);
|
||||||
init_py_geometry(m);
|
init_py_geometry(m);
|
||||||
|
|
||||||
/* Forward declarations */
|
/* Forward declarations */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue