-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
conversions between [u8; 4] and Color #8564
Conversation
crates/bevy_render/src/color/mod.rs
Outdated
pub fn as_rgba_u8(&self) -> [u8; 4] { | ||
let [r, g, b, a] = self.as_rgba_f32(); | ||
[ | ||
(r * 255.0) as u8, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For those wondering like me, values less than 0
will cast to 0
and values greater than 255
will cast to 255
. So this should be okay since we expect each component to be in the range [0, 1]
anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0
will cast to0
and values greater than255
will cast to255
.
I didn't actually know that but that's good to know haha
Co-authored-by: Gino Valente <[email protected]>
I like that this is more explicit: very easy to trip yourself up with color space casting. |
Objective
Solution
- Implement From for [u8; 4]- also implement From<[u8; 4]> for Color because why not.as_rgba_u8
in Color