1786012991

This commit is contained in:
2026-08-06 12:43:11 +02:00
parent dbe3f879a2
commit 86f391fc78
3 changed files with 60 additions and 20 deletions

View File

@@ -1,5 +1,6 @@
use embedded_graphics_core::pixelcolor::*;
use linfb::shape::Color;
use slint::platform::software_renderer::TargetPixel;
/// Simple RGBA color wrapper.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -80,28 +81,45 @@ impl Blend<Rgb888> for Rgba<Rgb888> {
}
}
impl From<(u8,u8,u8,u8)> for Rgba<Rgb888> {
fn from(value: (u8,u8,u8,u8)) -> Self {
Self(
Rgb888::new(
value.0,
value.1,
value.2,
),
value.3,
)
impl TargetPixel for Rgba<Rgb888> {
fn blend(&mut self, color: slint::platform::software_renderer::PremultipliedRgbaColor) {
let a = self.a() as u32;
// if a == 0 {
// return bg;
// }
// if a == 255 {
// return self.rgb();
// }
let fr = self.rgb().r() as u32;
let fg = self.rgb().g() as u32;
let fb = self.rgb().b() as u32;
let br = color.red as u32;
let bgc = color.green as u32;
let bb = color.blue as u32;
let r = (br + mul_blend_u8(fr.wrapping_sub(br), a)) as u8;
let g = (bgc + mul_blend_u8(fg.wrapping_sub(bgc), a)) as u8;
let b = (bb + mul_blend_u8(fb.wrapping_sub(bb), a)) as u8;
self.0 = Rgb888::new(r, g, b);
self.1 = a as u8;
}
fn from_rgb(red: u8, green: u8, blue: u8) -> Self {
Self(Rgb888::new(red, green, blue), 255)
}
}
impl From<(u8, u8, u8, u8)> for Rgba<Rgb888> {
fn from(value: (u8, u8, u8, u8)) -> Self {
Self(Rgb888::new(value.0, value.1, value.2), value.3)
}
}
impl From<Color> for Rgba<Rgb888> {
fn from(value: Color) -> Self {
Self(
Rgb888::new(
value.red,
value.green,
value.blue,
),
value.alpha,
)
Self(Rgb888::new(value.red, value.green, value.blue), value.alpha)
}
}