1
0
Fork 0
forked from wry/wry

it: use a software renderer

This commit is contained in:
Julian Orth 2024-06-05 18:23:13 +02:00
parent 5e336e19b7
commit 3430c3661b
5 changed files with 577 additions and 5 deletions

View file

@ -49,7 +49,7 @@ fn to_f32(c: u8) -> f32 {
#[allow(dead_code)]
fn to_u8(c: f32) -> u8 {
(c * 255f32) as u8
(c * 255f32).round() as u8
}
impl Color {
@ -80,6 +80,15 @@ impl Color {
}
}
pub fn from_rgba_premultiplied(r: u8, g: u8, b: u8, a: u8) -> Self {
Self {
r: to_f32(r),
g: to_f32(g),
b: to_f32(b),
a: to_f32(a),
}
}
pub fn from_u32_rgba_premultiplied(r: u32, g: u32, b: u32, a: u32) -> Self {
fn to_f32(c: u32) -> f32 {
((c as f64) / (u32::MAX as f64)) as f32
@ -127,6 +136,15 @@ impl Color {
self.a,
]
}
pub fn and_then(self, other: &Color) -> Color {
Color {
r: self.r * (1.0 - other.a) + other.r,
g: self.g * (1.0 - other.a) + other.g,
b: self.b * (1.0 - other.a) + other.b,
a: self.a * (1.0 - other.a) + other.a,
}
}
}
impl From<jay_config::theme::Color> for Color {