From 325f7945572049e4786390a11b87b3f2be05ca4d Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Tue, 12 Dec 2023 13:37:28 +0000 Subject: [PATCH] picamera2: Allow setting of stride Allow setting of the stride in stream configuration, and default to 0 if not set to allow libcamera to set the correct stride. Signed-off-by: William Vinnicombe --- picamera2/picamera2.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/picamera2/picamera2.py b/picamera2/picamera2.py index 95d3deec..047edadc 100644 --- a/picamera2/picamera2.py +++ b/picamera2/picamera2.py @@ -641,7 +641,7 @@ def _make_initial_stream_config(stream_config: dict, updates: dict, ignore_list= """ if updates is None: return None - valid = ("format", "size") + valid = ("format", "size", "stride") for key, value in updates.items(): if isinstance(value, SensorFormat): value = str(value) @@ -839,6 +839,11 @@ def _update_libcamera_stream_config(libcamera_stream_config, stream_config, buff libcamera_stream_config.size = libcamera.Size(stream_config["size"][0], stream_config["size"][1]) libcamera_stream_config.pixel_format = libcamera.PixelFormat(stream_config["format"]) libcamera_stream_config.buffer_count = buffer_count + # Stride is sometimes set to None in the stream_config, so need to guard against that case + if stream_config.get("stride") is not None: + libcamera_stream_config.stride = stream_config["stride"] + else: + libcamera_stream_config.stride = 0 def _make_libcamera_config(self, camera_config): # Make a libcamera configuration object from our Python configuration.