Updated color packing into u32 to consider incorrect web-colors.

This commit is contained in:
Bingus 2023-06-06 17:06:40 -07:00
parent 226ce3d6c9
commit 9554c78f3a
No known key found for this signature in database
GPG key ID: 5F84D2AA40A9F170
4 changed files with 61 additions and 49 deletions

View file

@ -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;