Skip to content

Converting to/from u32 sRGBA and HSLA #267

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

You must be logged in to vote

Hi, you seem to be hitting an unfortunate case with the error messages, but the solution should be relatively simple. Let me start by annotating your example with bit more explicit types to know what we are talking about:

let raw_value: i32 = -7589836;
let color = Srgba::from_u32::<Rgba>(raw_value as u32); // This is Srgba<u8> which is Alpha<Rgb<Srgb, u8>, u8>
println!("{:?}", color); //Alpha { color: Rgb { red: 255, green: 140, blue: 48, standard: PhantomData }, alpha: 52 }
        
let hsla_color: Hsla =  color.into_color(); // Hsla defaults to Hsla<Srgb, f32>, which is Alpha<Hsl<Srgb, f32>, f32>

Rust has this quirk where if you have a type with default type parameters, the defaults bec…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Ogeon
Comment options

Ogeon Jan 5, 2022
Maintainer

@Nic0w
Comment options

@Ogeon
Comment options

Ogeon Jan 5, 2022
Maintainer

Answer selected by Nic0w
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