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

Packed formats #144

Diggsey opened this issue Sep 14, 2019 · 1 comment · Fixed by #170

Packed formats #144

Diggsey opened this issue Sep 14, 2019 · 1 comment · Fixed by #170


Copy link

Diggsey commented Sep 14, 2019

It's common to store sRGB values packed in a u32 (eg. 0xAARRGGBB) - it would be helpful to provide functions to convert to this format.

I need to convert from linear, floating-point RGB to a packed sRGB u32, and the way I'm currently doing it is like this:

fn to_srgb(color: Vector3<f64>) -> u32 {
    let src = LinSrgb::new(color[0], color[1], color[2]);
    let dst: Srgb<u8> = Srgb::from_format(Srgb::from_linear(src));
    0xFF000000 | (( as u32) << 16) | (( as u32) << 8) | ( as u32)

I'm not sure if this is the best way to do it.

Copy link

Ogeon commented Sep 14, 2019

That would probably be a nice addition, but the implementation would have to be clear about what the channel order is. 🤔 Some put the alpha in one end, and some in the other. Some reverse the red, green and blue, and so on. The assumed channel order in Palette is currently RGBA and there is not yet any built-in way of encoding them in any other order, so being able to do it would be a new addition.

Your example function is about as good as it gets with the current API. It's possible to make changes like replacing from_format with .into_format() and such, but it's still the same procedure in the end. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging a pull request may close this issue.

2 participants