[libcamera-devel] [PATCH v7 12/13] py: add support for setting Rectangle and Size controls

Tomi Valkeinen tomi.valkeinen at ideasonboard.com
Thu May 5 12:41:03 CEST 2022


From: David Plowman <david.plowman at raspberrypi.com>

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

Signed-off-by: David Plowman <david.plowman at raspberrypi.com>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen at 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");
-- 
2.34.1



More information about the libcamera-devel mailing list