Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix alignment functionality on Pi 5 #1052

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions picamera2/picamera2.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,13 +933,13 @@ def score_format(desired, actual):
@staticmethod
def align_stream(stream_config: dict, optimal=True) -> None:
if optimal:
# Adjust the image size so that all planes are a mutliple of 32 bytes wide.
# Adjust the image size so that all planes are a mutliple of 32/64 bytes wide.
# This matches the hardware behaviour and means we can be more efficient.
align = 32
align = 32 if Picamera2.platform == Platform.Platform.VC4 else 64
if stream_config["format"] in ("YUV420", "YVU420"):
align = 64 # because the UV planes will have half this alignment
elif stream_config["format"] in ("XBGR8888", "XRGB8888"):
align = 16 # 4 channels per pixel gives us an automatic extra factor of 2
align *= 2 # because the UV planes will have half this alignment
elif stream_config["format"] in ("XBGR8888", "XRGB8888", "RGB161616", "BGR161616"):
align //= 2 # we have an automatic extra factor of 2 here
else:
align = 2
size = stream_config["size"]
Expand Down
42 changes: 42 additions & 0 deletions tests/alignment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/python3

from picamera2 import Picamera2, Platform

picam2 = Picamera2()


def compute_expected_stride(width, format):
if format in ("BGR888", "RGB888"):
return width * 3
elif format in ("XBGR8888", "XRGB8888"):
return width * 4
elif format in ("YUV420", "YVU420"):
return width
elif format in ("RGB161616", "BGR161616"):
return width * 6


def test_alignment(width, format):
config = picam2.create_preview_configuration({'size': (width, 480), 'format': format}, buffer_count=1)
picam2.align_configuration(config)
picam2.configure(config)
actual_stride = config['main']['stride']
actual_width = config['main']['size'][0]
expected_stride = compute_expected_stride(actual_width, format)
if actual_stride != expected_stride:
print("ERROR: stride", actual_stride, "!=", expected_stride, "for format", format)
return 1
return 0


formats = ["RGB888", "XRGB8888", "YUV420"]
if picam2.platform == Platform.PISP:
formats.append("RGB161616")

failures = 0
for format in formats:
for width in range(512, 1025, 2):
print(format)
failures += test_alignment(width, format)

print("Failures:", failures)
1 change: 1 addition & 0 deletions tests/test_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ examples/tuning_file.py
examples/video_with_config.py
examples/window_offset.py
examples/zoom.py
tests/alignment.py
tests/app_dual.py
tests/app_full_test.py
tests/app_test.py
Expand Down
Loading