You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to implement Rgb666Pixel for use with ILI9486 display controller over SPI and it uses Rgb666 color format. I've been struggling with that for quite a while and I'm desperate to find what I'm doing wrong. Now I have blue text as blue text, green text as green text, red text as red text, but there are some artifacts around literals and also it seems that colors are still blended incorrectly
Here's the code of TargetPixel implementation and software renderer:
use core::ops::Range;
use embedded_graphics_core::pixelcolor::{Rgb666, raw::RawU24};
use linux_embedded_hal::CdevPin;
use mipidsi::{
Display,
interface::{Interface, InterfacePixelFormat},
models::Model,
};
use slint::platform::software_renderer::{LineBufferProvider, PremultipliedRgbaColor, TargetPixel};
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)]
pub struct Rgb666Pixel {
red: u8,
green: u8,
blue: u8,
}
impl Rgb666Pixel {
fn red(&self) -> u8 {
self.red
}
fn green(&self) -> u8 {
self.green
}
fn blue(&self) -> u8 {
self.blue
}
}
impl TargetPixel for Rgb666Pixel {
fn blend(&mut self, color: PremultipliedRgbaColor) {
let a = (u8::MAX - color.alpha) as u16;
let r = ((self.red() as u16 * a) / 255) as u8 + color.red;
let g = ((self.green() as u16 * a) / 255) as u8 + color.green;
let b = ((self.blue() as u16 * a) / 255) as u8 + color.blue;
let r6 = (r >> 2) & 0x3F; // Take top 6 bits
let g6 = (g >> 2) & 0x3F;
let b6 = (b >> 2) & 0x3F;
self.red = r6;
self.green = g6;
self.blue = b6;
}
fn from_rgb(red: u8, green: u8, blue: u8) -> Self {
let r6 = (red >> 2) & 0x3F;
let g6 = (green >> 2) & 0x3F;
let b6 = (blue >> 2) & 0x3F;
Self {
red: r6,
green: g6,
blue: b6,
}
}
}
pub struct SlintRenderer<DI: Interface, MODEL: Model>
where
MODEL::ColorFormat: InterfacePixelFormat<DI::Word> + From<RawU24>,
{
display: Display<DI, MODEL, CdevPin>,
buffer: [Rgb666Pixel; 320],
}
impl<DI: Interface, MODEL: Model> SlintRenderer<DI, MODEL>
where
MODEL::ColorFormat: InterfacePixelFormat<DI::Word> + From<RawU24>,
{
pub fn new(display: Display<DI, MODEL, CdevPin>) -> Self {
Self {
display,
buffer: [Rgb666Pixel::default(); 320],
}
}
}
impl<DI: Interface, MODEL: Model> LineBufferProvider for &mut SlintRenderer<DI, MODEL>
where
MODEL::ColorFormat: InterfacePixelFormat<DI::Word> + From<RawU24>,
{
type TargetPixel = Rgb666Pixel;
fn process_line(
&mut self,
line: usize,
range: Range<usize>,
render_fn: impl FnOnce(&mut [Rgb666Pixel]),
) {
let buf = &mut self.buffer[range.clone()];
render_fn(buf);
self.display
.set_pixels(
range.start as u16,
line as u16,
range.end as u16,
line as u16,
buf.iter().map(|x| {
let color = Rgb666::new(x.red(), x.green(), x.blue());
MODEL::ColorFormat::from(color.into())
}),
)
.unwrap();
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to implement Rgb666Pixel for use with ILI9486 display controller over SPI and it uses Rgb666 color format. I've been struggling with that for quite a while and I'm desperate to find what I'm doing wrong. Now I have blue text as blue text, green text as green text, red text as red text, but there are some artifacts around literals and also it seems that colors are still blended incorrectly
Here's the code of TargetPixel implementation and software renderer:
Also there's an image

Beta Was this translation helpful? Give feedback.
All reactions