Skip to main content

gpui/text_system/
text_color.rs

1/// Eight-bit sRGB color stored in a raster cache key when a native raster path needs it.
2pub type Rgba8 = palette::Srgba<u8>;
3
4/// Converts a scene color to the bytes used by a raster cache key.
5pub trait RasterColorExt {
6    /// Clamps and rounds each channel to the nearest byte.
7    fn quantize_raster_color(self) -> Rgba8;
8}
9
10impl RasterColorExt for crate::Rgba {
11    fn quantize_raster_color(self) -> Rgba8 {
12        fn channel(value: f32) -> u8 {
13            (value.clamp(0.0, 1.0) * 255.0).round() as u8
14        }
15
16        Rgba8::new(
17            channel(self.red),
18            channel(self.green),
19            channel(self.blue),
20            channel(self.alpha),
21        )
22    }
23}