Skip to content

Only change image pixels in {from,into}_raw_{bgr,bgra}#3005

Merged
197g merged 1 commit into
image-rs:mainfrom
RunDevelopment:bgra-subpixels
May 31, 2026
Merged

Only change image pixels in {from,into}_raw_{bgr,bgra}#3005
197g merged 1 commit into
image-rs:mainfrom
RunDevelopment:bgra-subpixels

Conversation

@RunDevelopment
Copy link
Copy Markdown
Member

Addresses C4 and L7 from #2954.

This changes {from,into}_raw_{bgr,bgra} to only perform the BGR <-> RGB conversion on pixels in the image. This has 2 effects:

  1. If the buffer is too large, then data outside the image is no longer modified. We don't guarantee this, but I think users would expect that we don't do unnecessary work.
  2. If the buffer is too small (i.e. invalid), then the into_raw_* methods will now panic. This can only happen if the user breaks the invariant of the type. I think panicking is preferable to returning data that does not comply with the invariant of the ImageBuffer.

Copy link
Copy Markdown
Member

@197g 197g left a comment

Choose a reason for hiding this comment

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

As noted in my review comments on C4, L7, I was not convinced this is a change we want to do. The panic in particular, hm.. But it is more consistent to handle both in the same manner as other constructions where we do not touch superfluous data.

@197g 197g merged commit b0e2f00 into image-rs:main May 31, 2026
31 checks passed
@RunDevelopment RunDevelopment deleted the bgra-subpixels branch May 31, 2026 11:11
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