Skip to content

Make sure that everything is always in the correct pixel format#31

Closed
jaytaph wants to merge 5 commits into
benchmarkingfrom
rgb-fix
Closed

Make sure that everything is always in the correct pixel format#31
jaytaph wants to merge 5 commits into
benchmarkingfrom
rgb-fix

Conversation

@jaytaph

@jaytaph jaytaph commented Jun 14, 2026

Copy link
Copy Markdown
Owner

There are some inconsistencies between mac and linux binaries when it comes to RGB/BGR formats.

@Sharktheone

Copy link
Copy Markdown
Collaborator

I feel like this has a lot of other changes form the other PR's. I think the stacking might not have worked properly

@jaytaph

jaytaph commented Jun 27, 2026

Copy link
Copy Markdown
Owner Author

I feel like this has a lot of other changes form the other PR's. I think the stacking might not have worked properly

It did.. but the other PR's are rebased on upstream/main, so I need to manually update each PR on every merge.

@jaytaph

jaytaph commented Jun 27, 2026

Copy link
Copy Markdown
Owner Author

@Sharktheone it's rebased now

&mut self,
width: usize,
height: usize,
data: Vec<u8>,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Btw, in general i think this should not be a Vec here, but more a Arc<[u8]>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Or maybe even Bytes from the bytes crate

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

I move this to bytes

let texture_id = texture_store.add(
w,
h,
data.to_vec(),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we might also have this be something else entirely. so we don't have to copy the data here

Comment on lines +72 to +88
pub fn to_rgba<'a>(self, data: &'a [u8]) -> std::borrow::Cow<'a, [u8]> {
match self {
PixelFormat::Rgba8 => std::borrow::Cow::Borrowed(data),
PixelFormat::PreMulArgb32 => std::borrow::Cow::Owned(swap_rb(data)),
}
}

/// Returns `data` with bytes in `[B, G, R, A]` order (little-endian ARGB32),
/// copying (and swapping R/B) only when the source is not already in that order.
pub fn to_argb32<'a>(self, data: &'a [u8]) -> std::borrow::Cow<'a, [u8]> {
match self {
PixelFormat::PreMulArgb32 => std::borrow::Cow::Borrowed(data),
PixelFormat::Rgba8 => std::borrow::Cow::Owned(swap_rb(data)),
}
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I feel like we can do this more efficiently by passing in a &mut [u8] and swapping it in place

@jaytaph jaytaph closed this Jun 30, 2026
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