style: Add lab(), lch(), oklab(), oklch() to specified colors

Use new changes from cssparser and use the new lab/lch/oklab/oklch color
formats.

Introduced a new color type AbsoluteColor.  It represents any kind of
color that has absolute numerical values.  It is also tied to a color
space and therefore can be trivially converted to another color space.

Differential Revision: https://phabricator.services.mozilla.com/D163579
This commit is contained in:
Tiaan Louw 2023-01-20 10:55:51 +00:00 committed by Martin Robinson
parent 6ce64abe7e
commit 4559546fbb
12 changed files with 512 additions and 90 deletions

View file

@ -18,20 +18,18 @@ use std::cmp::max;
/// Convert a given RGBA value to `nscolor`.
pub fn convert_rgba_to_nscolor(rgba: &RGBA) -> u32 {
((rgba.alpha as u32) << 24) |
((rgba.blue as u32) << 16) |
((rgba.green as u32) << 8) |
(rgba.red as u32)
u32::from_le_bytes([
rgba.red,
rgba.green,
rgba.blue,
(rgba.alpha * 255.0).round() as u8,
])
}
/// Convert a given `nscolor` to a Servo RGBA value.
pub fn convert_nscolor_to_rgba(color: u32) -> RGBA {
RGBA::new(
(color & 0xff) as u8,
(color >> 8 & 0xff) as u8,
(color >> 16 & 0xff) as u8,
(color >> 24 & 0xff) as u8,
)
let [r, g, b, a] = color.to_le_bytes();
RGBA::new(r, g, b, a as f32 / 255.0)
}
/// Round `width` down to the nearest device pixel, but any non-zero value that