feat: Add Color::into_rgb8

This commit is contained in:
Michael Aaron Murphy 2022-11-16 16:35:56 +01:00 committed by Héctor Ramón Jiménez
parent 28f0beee52
commit 0249640213
No known key found for this signature in database
GPG key ID: 140CC052C94F138E

View file

@ -89,6 +89,19 @@ impl Color {
}
}
/// Converts the [`Color`] into its RGBA8 equivalent.
#[must_use]
#[allow(clippy::cast_sign_loss)]
#[allow(clippy::cast_possible_truncation)]
pub fn into_rgba8(self) -> [u8; 4] {
[
(self.r * 255.0).round() as u8,
(self.g * 255.0).round() as u8,
(self.b * 255.0).round() as u8,
(self.a * 255.0).round() as u8,
]
}
/// Converts the [`Color`] into its linear values.
pub fn into_linear(self) -> [f32; 4] {
// As described in: