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

Adds back in way to convert color to u8 array, implemented for the two RGB color types, also renames Color::linear to Color::to_linear. #13759

Merged
merged 6 commits into from
Jun 10, 2024

Conversation

gagnus
Copy link
Contributor

@gagnus gagnus commented Jun 8, 2024

Objective

One thing missing from the new Color implementation in 0.14 is the ability to easily convert to a u8 representation of the rgb color.

(note this is a redo of PR #13739 as I needed to move the source branch

Solution

I have added to_u8_array and to_u8_array_no_alpha to a new trait called ColorToPacked to mirror the f32 conversions in ColorToComponents and implemented the new trait for Srgba and LinearRgba.
To go with those I also added matching from_u8... functions and converted a couple of cases that used ad-hoc implementations of that conversion to use these.
After discussion on Discord of the experience of using the API I renamed Color::linear to Color::to_linear, as without that it looks like a constructor (like Color::rgb).
I also added to_srgba which is the other commonly converted to type of color (for UI and 2D) to match to_linear.
Removed a redundant extra implementation of to_f32_array for LinearColor as it is also supplied in ColorToComponents (I'm surprised that's allowed?)

Testing

Ran all tests and manually tested.
Added to_and_from_u8 to linear_rgba::tests

Changelog

visible change is Color::linear becomes Color::to_linear.

gagnus and others added 6 commits June 7, 2024 14:01
…e other major option. Added to_u8_array, from_u8_array and _no_alpha versions of them to ColorToComponent, implemented for SRgba and LinearRgba and left unimplemented! for other color types which don't make sense. Removed redundant extra version of to_f32_array in LinearRgba and added use ColorToComponent where that was used in other code, some extra tidy up of usage to use these new functions.
…e other color types dont need unimplemented versions.
@gagnus
Copy link
Contributor Author

gagnus commented Jun 8, 2024

@alice-i-cecile I'm really sorry I had to recreate my PR to pull from a different branch. Code all the same.
Originally reviewed by @viridia (apologies again)

@alice-i-cecile alice-i-cecile added this to the 0.14 milestone Jun 8, 2024
@gagnus
Copy link
Contributor Author

gagnus commented Jun 9, 2024

Wondering whether Color::to_linear() should be Color::to_linear_rgba to match the constructor naming and the type naming? (Color::linear_rgba(r, g, b, a), LinearRgba)

@NthTensor
Copy link
Contributor

to_linear_rgba is my preference.

@NthTensor NthTensor added 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 X-Uncontroversial This work is generally agreed upon D-Straightforward Simple bug fixes and API improvements, docs, test and examples A-Color Color spaces and color math labels Jun 9, 2024
@alice-i-cecile
Copy link
Member

Yeah, let's swap to to_linear_rgba and then I'll merge this in.

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jun 10, 2024
Merged via the queue into bevyengine:main with commit 298b01f Jun 10, 2024
33 checks passed
mockersf pushed a commit that referenced this pull request Jun 10, 2024
…o RGB color types, also renames Color::linear to Color::to_linear. (#13759)

# Objective

One thing missing from the new Color implementation in 0.14 is the
ability to easily convert to a u8 representation of the rgb color.

(note this is a redo of PR #13739
as I needed to move the source branch

## Solution

I have added to_u8_array and to_u8_array_no_alpha to a new trait called
ColorToPacked to mirror the f32 conversions in ColorToComponents and
implemented the new trait for Srgba and LinearRgba.
To go with those I also added matching from_u8... functions and
converted a couple of cases that used ad-hoc implementations of that
conversion to use these.
After discussion on Discord of the experience of using the API I renamed
Color::linear to Color::to_linear, as without that it looks like a
constructor (like Color::rgb).
I also added to_srgba which is the other commonly converted to type of
color (for UI and 2D) to match to_linear.
Removed a redundant extra implementation of to_f32_array for LinearColor
as it is also supplied in ColorToComponents (I'm surprised that's
allowed?)

## Testing

Ran all tests and manually tested.
Added to_and_from_u8 to linear_rgba::tests

## Changelog

visible change is Color::linear becomes Color::to_linear.

---------

Co-authored-by: John Payne <20407779+johngpayne@users.noreply.github.com>
@rparrett rparrett added the C-Breaking-Change A breaking change to Bevy's public API that needs to be noted in a migration guide label Jun 17, 2024
Copy link
Contributor

It looks like your PR is a breaking change, but you didn't provide a migration guide.

Could you add some context on what users should update when this change get released in a new version of Bevy?
It will be used to help writing the migration guide for the version. Putting it after a ## Migration Guide will help it get automatically picked up by our tooling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Color Color spaces and color math C-Breaking-Change A breaking change to Bevy's public API that needs to be noted in a migration guide C-Usability A simple quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it X-Uncontroversial This work is generally agreed upon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants