From 87b709f06f5b281ef77054540c787b9d31ec6ad2 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Wed, 13 Dec 2023 17:14:28 +0000 Subject: [PATCH] Add stride test Add a test to check the stride is being set correctly when provided in the stream configuration Signed-off-by: William Vinnicombe --- tests/stride_test.py | 41 +++++++++++++++++++++++++++++++++++++++++ tests/test_list.txt | 1 + 2 files changed, 42 insertions(+) create mode 100755 tests/stride_test.py diff --git a/tests/stride_test.py b/tests/stride_test.py new file mode 100755 index 00000000..b1b7e4ea --- /dev/null +++ b/tests/stride_test.py @@ -0,0 +1,41 @@ +#!/usr/bin/python3 + +import time + +from picamera2 import MappedArray, Picamera2, libcamera + + +def pre_callback(request): + # Set the size, to make preview window and MappedArray remapping work + assert request.config["main"]["stride"] == stride + request.config["main"]["size"] = full_size + request.stream_map["main"].configuration.size = libcamera.Size(*full_size) + + +def post_callback(request): + # Make right side grey + with MappedArray(request, "main") as m1: + a1 = m1.array + a1[:, -a1.shape[1] // 2:] = 70 + + +picam2 = Picamera2(0) + +full_size = (1920, 1080) +half_size = (full_size[0] // 2, full_size[1]) +# Calculate stride for full frame +full_config = picam2.create_preview_configuration({"size": full_size}) +picam2.configure(full_config) +stride = picam2.camera_config["main"]["stride"] + +# Configure as half frame, with full frame stride so right side is blank +picam2.pre_callback = pre_callback +picam2.post_callback = post_callback +main_config = picam2.create_preview_configuration( + main={"size": half_size, "stride": stride} +) +picam2.configure(main_config) +picam2.start_preview(True) + +picam2.start() +time.sleep(2) diff --git a/tests/test_list.txt b/tests/test_list.txt index 10d7317d..272dc6b4 100644 --- a/tests/test_list.txt +++ b/tests/test_list.txt @@ -86,3 +86,4 @@ tests/stop_slow_framerate.py tests/allocator_test.py tests/allocator_leak_test.py tests/wait_cancel_test.py +tests/stride_test.py