Switch to sRGBA everywhere

This commit is contained in:
Joscha 2024-03-08 17:40:17 +01:00
parent 859fdb4bfe
commit 1e73c01845
6 changed files with 52 additions and 44 deletions

View file

@ -1,21 +1,21 @@
use palette::Srgb;
use palette::Srgba;
pub fn from_image_rgb(color: image::Rgb<u8>) -> Srgb {
let [r, g, b] = color.0;
Srgb::new(r, g, b).into_format()
pub fn from_image_color(color: image::Rgba<u8>) -> Srgba {
let [r, g, b, a] = color.0;
Srgba::new(r, g, b, a).into_format()
}
pub fn to_image_rgb(color: Srgb) -> image::Rgb<u8> {
let color = color.into_format::<u8>();
image::Rgb([color.red, color.green, color.blue])
pub fn to_image_color(color: Srgba) -> image::Rgba<u8> {
let color = color.into_format::<u8, u8>();
image::Rgba([color.red, color.green, color.blue, color.alpha])
}
pub fn from_text_color(color: cosmic_text::Color) -> Srgb {
let [r, g, b, _] = color.as_rgba();
Srgb::new(r, g, b).into_format()
pub fn from_text_color(color: cosmic_text::Color) -> Srgba {
let [r, g, b, a] = color.as_rgba();
Srgba::new(r, g, b, a).into_format()
}
pub fn to_text_color(color: Srgb) -> cosmic_text::Color {
let color = color.into_format::<u8>();
cosmic_text::Color::rgb(color.red, color.green, color.blue)
pub fn to_text_color(color: Srgba) -> cosmic_text::Color {
let color = color.into_format::<u8, u8>();
cosmic_text::Color::rgba(color.red, color.green, color.blue, color.alpha)
}