diff options
author | 2022-11-16 16:35:56 +0100 | |
---|---|---|
committer | 2022-12-06 03:59:53 +0100 | |
commit | 0249640213120e039462f5fc12c677f15ecbc7cc (patch) | |
tree | 162167b163f70000517deb52b3f8847747e345a6 /core | |
parent | 28f0beee52f258af6bbaf8a0d9867863d7513c9b (diff) | |
download | iced-0249640213120e039462f5fc12c677f15ecbc7cc.tar.gz iced-0249640213120e039462f5fc12c677f15ecbc7cc.tar.bz2 iced-0249640213120e039462f5fc12c677f15ecbc7cc.zip |
feat: Add Color::into_rgb8
Diffstat (limited to '')
-rw-r--r-- | core/src/color.rs | 13 |
1 files changed, 13 insertions, 0 deletions
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: |