Skip to content

How can I use the Pixel trait with different channel orderings (e.g. BGR, RGB, ABGR, ..) #263

Answered by Ogeon
terhechte asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, this use case is sadly not fully developed in the currently released version. Pixel, as you have noticed, doesn't change the data. It will only change the type the compiler sees it as. Packed was added to cover the case where one want to represent a color as the bytes in a u32. It gives you the channel reordering but not the byte array representation. It only works with [u32] buffers, where a single u32 is a single pixel. This will be improved in the next version, currently on the master branch, as you can see in this example.

To explain the error above, you would have to convert to palette::Srgba<u8>, not palette::Srgba<u32>. The former has u8 channels while the latter has u32 channe…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@terhechte
Comment options

@Ogeon
Comment options

Answer selected by terhechte
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants