[libcamera-devel,v7,12/13] py: add support for setting Rectangle and Size controls
diff mbox series

Message ID 20220505104104.70841-13-tomi.valkeinen@ideasonboard.com
State Superseded
Headers show
Series
  • Python bindings
Related show

Commit Message

Tomi Valkeinen May 5, 2022, 10:41 a.m. UTC
From: David Plowman <david.plowman@raspberrypi.com>

Allows, for example, ScalerCrop to be controlled for digital zoom.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 src/py/libcamera/pymain.cpp | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Laurent Pinchart May 5, 2022, 6:03 p.m. UTC | #1
Hi Tomi and David,

Thank you for the patch.

On Thu, May 05, 2022 at 01:41:03PM +0300, Tomi Valkeinen wrote:
> From: David Plowman <david.plowman@raspberrypi.com>
> 
> Allows, for example, ScalerCrop to be controlled for digital zoom.
> 
> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>

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

> ---
>  src/py/libcamera/pymain.cpp | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/src/py/libcamera/pymain.cpp b/src/py/libcamera/pymain.cpp
> index 6375e326..b9b52f6b 100644
> --- a/src/py/libcamera/pymain.cpp
> +++ b/src/py/libcamera/pymain.cpp
> @@ -101,8 +101,14 @@ static ControlValue PyToControlValue(const py::object &ob, ControlType type)
>  		return ControlValueMaybeArray<float>(ob);
>  	case ControlTypeString:
>  		return ControlValue(ob.cast<string>());
> -	case ControlTypeRectangle:
> -	case ControlTypeSize:
> +	case ControlTypeRectangle: {
> +		auto array = ob.cast<std::array<int32_t, 4>>();
> +		return ControlValue(Rectangle(array[0], array[1], array[2], array[3]));
> +	}
> +	case ControlTypeSize: {
> +		auto array = ob.cast<std::array<int32_t, 2>>();
> +		return ControlValue(Size(array[0], array[1]));
> +	}
>  	case ControlTypeNone:
>  	default:
>  		throw runtime_error("Control type not implemented");

Patch
diff mbox series

diff --git a/src/py/libcamera/pymain.cpp b/src/py/libcamera/pymain.cpp
index 6375e326..b9b52f6b 100644
--- a/src/py/libcamera/pymain.cpp
+++ b/src/py/libcamera/pymain.cpp
@@ -101,8 +101,14 @@  static ControlValue PyToControlValue(const py::object &ob, ControlType type)
 		return ControlValueMaybeArray<float>(ob);
 	case ControlTypeString:
 		return ControlValue(ob.cast<string>());
-	case ControlTypeRectangle:
-	case ControlTypeSize:
+	case ControlTypeRectangle: {
+		auto array = ob.cast<std::array<int32_t, 4>>();
+		return ControlValue(Rectangle(array[0], array[1], array[2], array[3]));
+	}
+	case ControlTypeSize: {
+		auto array = ob.cast<std::array<int32_t, 2>>();
+		return ControlValue(Size(array[0], array[1]));
+	}
 	case ControlTypeNone:
 	default:
 		throw runtime_error("Control type not implemented");