[libcamera-devel] [PATCH v7 08/13] py: support setting array-controls

Laurent Pinchart laurent.pinchart at ideasonboard.com
Thu May 5 19:55:19 CEST 2022


Hi Tomi,

Thank you for the patch.

On Thu, May 05, 2022 at 01:40:59PM +0300, Tomi Valkeinen wrote:
> Improve PyToControlValue() to convert python lists and tuples to a
> ControlValue with a Span<> value.
> 
> Original version from David Plowman <david.plowman at raspberrypi.com>.

Assuming the original version has David's SoB, please keep it here. I
would also keep David as the author of the patch.

Same for the remaining patches in the series.

> Signed-off-by: Tomi Valkeinen <tomi.valkeinen at ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>

> ---
>  src/py/libcamera/pymain.cpp | 19 +++++++++++++++----
>  1 file changed, 15 insertions(+), 4 deletions(-)
> 
> diff --git a/src/py/libcamera/pymain.cpp b/src/py/libcamera/pymain.cpp
> index 81d48a20..db9d90ab 100644
> --- a/src/py/libcamera/pymain.cpp
> +++ b/src/py/libcamera/pymain.cpp
> @@ -75,19 +75,30 @@ static py::object ControlValueToPy(const ControlValue &cv)
>  	}
>  }
>  
> +template<typename T>
> +static ControlValue ControlValueMaybeArray(const py::object &ob)
> +{
> +	if (py::isinstance<py::list>(ob) || py::isinstance<py::tuple>(ob)) {
> +		std::vector<T> vec = ob.cast<std::vector<T>>();
> +		return ControlValue(Span<const T>(vec));
> +	}
> +
> +	return ControlValue(ob.cast<T>());
> +}
> +
>  static ControlValue PyToControlValue(const py::object &ob, ControlType type)
>  {
>  	switch (type) {
>  	case ControlTypeBool:
>  		return ControlValue(ob.cast<bool>());
>  	case ControlTypeByte:
> -		return ControlValue(ob.cast<uint8_t>());
> +		return ControlValueMaybeArray<uint8_t>(ob);
>  	case ControlTypeInteger32:
> -		return ControlValue(ob.cast<int32_t>());
> +		return ControlValueMaybeArray<int32_t>(ob);
>  	case ControlTypeInteger64:
> -		return ControlValue(ob.cast<int64_t>());
> +		return ControlValueMaybeArray<int64_t>(ob);
>  	case ControlTypeFloat:
> -		return ControlValue(ob.cast<float>());
> +		return ControlValueMaybeArray<float>(ob);
>  	case ControlTypeString:
>  		return ControlValue(ob.cast<string>());
>  	case ControlTypeRectangle:

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list