From 0249640213120e039462f5fc12c677f15ecbc7cc Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Wed, 16 Nov 2022 16:35:56 +0100 Subject: feat: Add Color::into_rgb8 --- core/src/color.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/src/color.rs b/core/src/color.rs index 212c1214..e578eda4 100644 --- a/core/src/color.rs +++ b/core/src/color.rs @@ -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: -- cgit