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

conversions between [u8; 4] and Color #8564

Merged
merged 4 commits into from
May 8, 2023
Merged

conversions between [u8; 4] and Color #8564

merged 4 commits into from
May 8, 2023

Conversation

atornity
Copy link
Contributor

@atornity atornity commented May 7, 2023

Objective

Solution

- Implement From for [u8; 4]
- also implement From<[u8; 4]> for Color because why not.

  • implement method as_rgba_u8 in Color

crates/bevy_render/src/color/mod.rs Outdated Show resolved Hide resolved
pub fn as_rgba_u8(&self) -> [u8; 4] {
let [r, g, b, a] = self.as_rgba_f32();
[
(r * 255.0) as u8,
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

0 will cast to 0 and values greater than 255 will cast to 255.

I didn't actually know that but that's good to know haha

Co-authored-by: Gino Valente <49806985+MrGVSV@users.noreply.github.com>
@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen C-Usability A simple quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels May 8, 2023
@alice-i-cecile
Copy link
Member

I like that this is more explicit: very easy to trip yourself up with color space casting.

@mockersf mockersf added this pull request to the merge queue May 8, 2023
Merged via the queue into bevyengine:main with commit 8930cfc May 8, 2023
@atornity atornity deleted the color-convert branch May 8, 2023 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Usability A simple quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

implement From<Color> for [u8; 4]
4 participants