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(+) (limited to 'core/src') 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 From c0ca1807d42b0ec58887df9926ff53a587104723 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 6 Dec 2022 04:34:42 +0100 Subject: Fix macro hygiene of `color!` --- core/src/color.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'core/src') diff --git a/core/src/color.rs b/core/src/color.rs index e578eda4..2a4d43f4 100644 --- a/core/src/color.rs +++ b/core/src/color.rs @@ -161,24 +161,26 @@ impl From<[f32; 4]> for Color { #[macro_export] macro_rules! color { ($r:expr, $g:expr, $b:expr) => { - Color::from_rgb8($r, $g, $b) + $crate::Color::from_rgb8($r, $g, $b) }; ($r:expr, $g:expr, $b:expr, $a:expr) => { - Color::from_rgba8($r, $g, $b, $a) + $crate::Color::from_rgba8($r, $g, $b, $a) }; ($hex:expr) => {{ let hex = $hex as u32; let r = (hex & 0xff0000) >> 16; let g = (hex & 0xff00) >> 8; let b = (hex & 0xff); - Color::from_rgb8(r as u8, g as u8, b as u8) + + $crate::Color::from_rgb8(r as u8, g as u8, b as u8) }}; ($hex:expr, $a:expr) => {{ let hex = $hex as u32; let r = (hex & 0xff0000) >> 16; let g = (hex & 0xff00) >> 8; let b = (hex & 0xff); - Color::from_rgba8(r as u8, g as u8, b as u8, $a) + + $crate::Color::from_rgba8(r as u8, g as u8, b as u8, $a) }}; } -- cgit From 2d58a2c03325a77893461194bd601b312a0097ca Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 6 Dec 2022 04:40:32 +0100 Subject: Remove unnecessary `clippy` directives in `Color` --- core/src/color.rs | 2 -- 1 file changed, 2 deletions(-) (limited to 'core/src') diff --git a/core/src/color.rs b/core/src/color.rs index 2a4d43f4..fe0a1856 100644 --- a/core/src/color.rs +++ b/core/src/color.rs @@ -91,8 +91,6 @@ 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, -- cgit