Skip to content

Conversation

@kbingham
Copy link
Collaborator

Platforms may configure buffers that have a larger buffer stride than the image width to support hardware padding restrictions.

The raw_to_bgr888() function already accounts for this when operating on prepare_packed_raw(), however prepare_unpacked_raw() raw is missing the handling for buffer strides.

Reshape the data, and delete the padding accordingly.

data = data.reshape((height, len(data) // height))

# Remove padding if present
padded_width = width * bits_per_pixel // 8
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you test this?

The unpacked data is in 16-bit containers for 10/12/16. The above calculates a packed width.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, so most of my current test on this only displays the top left corner of a 20Megapixel image - so I could easily have got this wrong in fact.

This patch does however now let me /see/ the top left corner which is what I needed ;-) but yes - it probably needs retesting without my artificial crops added to verify the whole image.

I'm testing on a Raspberry Pi 5 capturing SRGGB16.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok - so perhaps this only worked for me because I was fortunately using SRGGB16 to match the 16 bit alignement of the data coming in by chance.

So perhaps regardless of bits_per_pixel, we should always do padded_width = width * 2; /* 16 bit data */

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope - now I see it. Particularly retesting on a system with 12 bit data instead of 16 bit data ;-)

     # Remove padding if present
-    padded_width = width * bits_per_pixel // 8
+    # The unpacked data is stored in 8 bits for 8bpp, and 16 bits for 10/12/16bpp.
+    bytes_per_pixel = 1 if bits_per_pixel == 8 else 2
+    padded_width = width * bytes_per_pixel

Copy link
Collaborator Author

@kbingham kbingham Apr 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or more generically to support future higher bit depths:

# The unpacked data is stored in 8 bits for 8bpp, and 16 bits for 10/12/16bpp
bytes_per_pixel = (bits_per_pixel + 7) // 8
padded_width = width * bytes_per_pixel

Platforms may configure buffers that have a larger buffer stride than
the image width to support hardware padding restrictions.

The raw_to_bgr888() function already accounts for this when operating on
prepare_packed_raw(), however prepare_unpacked_raw() raw is missing the
handling for buffer strides.

Reshape the data, and delete the padding accordingly.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
@kbingham kbingham force-pushed the kbingham/raw-strides branch from a395394 to 548f27b Compare April 25, 2025 11:31
@kbingham
Copy link
Collaborator Author

kbingham commented May 1, 2025

@tomba Any happier with this now ?

@tomba tomba merged commit ca8b18b into tomba:master May 1, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants