diff options
author | 2023-06-06 17:06:40 -0700 | |
---|---|---|
committer | 2023-06-06 17:24:26 -0700 | |
commit | 9554c78f3adc9846b76e9d3b96af06e98fb69aa0 (patch) | |
tree | cb51e072386014989aa42d259b9e17a70ae2d821 /core | |
parent | 226ce3d6c96e1ee091980c3d1ba869c01920b316 (diff) | |
download | iced-9554c78f3adc9846b76e9d3b96af06e98fb69aa0.tar.gz iced-9554c78f3adc9846b76e9d3b96af06e98fb69aa0.tar.bz2 iced-9554c78f3adc9846b76e9d3b96af06e98fb69aa0.zip |
Updated color packing into u32 to consider incorrect web-colors.
Diffstat (limited to 'core')
-rw-r--r-- | core/src/color.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/core/src/color.rs b/core/src/color.rs index 9ea6ccbf..9ef66b28 100644 --- a/core/src/color.rs +++ b/core/src/color.rs @@ -132,6 +132,25 @@ impl Color { r | g | b | a } + /// Converts the [`Color`] into a `u32` value containing its linear RGBA8 components. + pub fn into_linear_u32(self) -> u32 { + let [r, g, b, a] = self.into_linear(); + + let [r, g, b, a] = [ + (r * 255.0).round() as u8, + (g * 255.0).round() as u8, + (b * 255.0).round() as u8, + (a * 255.0).round() as u8, + ]; + + let r = (r as u32) << 24; + let g = (g as u32) << 16; + let b = (b as u32) << 8; + let a = a as u32; + + r | g | b | a + } + /// Inverts the [`Color`] in-place. pub fn invert(&mut self) { self.r = 1.0f32 - self.r; |