-
Notifications
You must be signed in to change notification settings - Fork 5
Add support color mode. #96
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,33 @@ | ||
| use bevy::color::{LinearRgba, Srgba}; | ||
| use processing::prelude::color::{ColorMode, ColorSpace}; | ||
|
|
||
| /// A sRGB (?) color | ||
| /// A color with 4 float components and its color space. | ||
| #[repr(C)] | ||
| #[derive(Debug, Clone, Copy)] | ||
| pub struct Color { | ||
| pub r: f32, | ||
| pub g: f32, | ||
| pub b: f32, | ||
| pub c1: f32, | ||
| pub c2: f32, | ||
| pub c3: f32, | ||
| pub a: f32, | ||
| pub space: u8, | ||
| } | ||
|
|
||
| impl From<Color> for bevy::color::Color { | ||
| fn from(color: Color) -> Self { | ||
| bevy::color::Color::srgba(color.r, color.g, color.b, color.a) | ||
| impl Color { | ||
| pub fn resolve(self, mode: &ColorMode) -> bevy::color::Color { | ||
| let c1 = mode.scale(self.c1, 0); | ||
| let c2 = mode.scale(self.c2, 1); | ||
| let c3 = mode.scale(self.c3, 2); | ||
| let ca = mode.scale(self.a, 3); | ||
| mode.space.color(c1, c2, c3, ca) | ||
| } | ||
| } | ||
|
|
||
| impl From<LinearRgba> for Color { | ||
| fn from(lin: LinearRgba) -> Self { | ||
| let srgb: Srgba = lin.into(); | ||
| srgb.into() | ||
| } | ||
| } | ||
|
|
||
| impl From<Srgba> for Color { | ||
| fn from(srgb: Srgba) -> Self { | ||
| pub fn from_linear(lin: LinearRgba) -> Self { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the idea we would implement this for every color space?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just a specific helper because some operations like GPU readback return raw bytes in a linear format.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ahh i see! |
||
| Color { | ||
| r: srgb.red, | ||
| g: srgb.green, | ||
| b: srgb.blue, | ||
| a: srgb.alpha, | ||
| c1: lin.red, | ||
| c2: lin.green, | ||
| c3: lin.blue, | ||
| a: lin.alpha, | ||
| space: ColorSpace::Linear 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.
this was surprising to me! Isn't
From<T>the way to handle generally?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.
Mmm, probably a more stylistic thing but before we were saying a color is ALWAYS a srgb repr and now it's more just like, this is one way you can construct a color? Since all the specific color spaces impl
Into<bevy::Color>we could probably implFrom<bevy::Color>for our color and it would probably "just work"