mirror of
https://github.com/bevyengine/bevy
synced 2024-11-30 00:20:20 +00:00
conversions between [u8; 4] and Color (#8564)
# Objective - Fixes #8563 ## Solution ~~- Implement From<Color> for [u8; 4]~~ ~~- also implement From<[u8; 4]> for Color because why not.~~ - implement method `as_rgba_u8` in Color --------- Co-authored-by: Gino Valente <49806985+MrGVSV@users.noreply.github.com>
This commit is contained in:
parent
e0a94abf1c
commit
8930cfcdd4
1 changed files with 11 additions and 0 deletions
|
@ -683,6 +683,17 @@ impl Color {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Converts a `Color` to a `[u8; 4]` from sRGB colorspace
|
||||||
|
pub fn as_rgba_u8(&self) -> [u8; 4] {
|
||||||
|
let [r, g, b, a] = self.as_rgba_f32();
|
||||||
|
[
|
||||||
|
(r * u8::MAX as f32) as u8,
|
||||||
|
(g * u8::MAX as f32) as u8,
|
||||||
|
(b * u8::MAX as f32) as u8,
|
||||||
|
(a * u8::MAX as f32) as u8,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
/// Converts a `Color` to a `[f32; 4]` from sRGB colorspace
|
/// Converts a `Color` to a `[f32; 4]` from sRGB colorspace
|
||||||
pub fn as_rgba_f32(self: Color) -> [f32; 4] {
|
pub fn as_rgba_f32(self: Color) -> [f32; 4] {
|
||||||
match self {
|
match self {
|
||||||
|
|
Loading…
Reference in a new issue