Add RGBW support

This commit is contained in:
Juergen Stuber 2023-04-16 20:00:02 +02:00
parent 534ddba827
commit a6e654f4be

View File

@ -27,6 +27,9 @@ struct Cli {
rows: usize, rows: usize,
/// Free-format arguments to pass to the executable /// Free-format arguments to pass to the executable
args: Vec<String>, args: Vec<String>,
/// Use RGBW pixel format
#[arg(short, long, action = clap::ArgAction::SetTrue)]
white: bool,
/// Frame rate for displaying /// Frame rate for displaying
#[arg(short, long, default_value_t = 25)] #[arg(short, long, default_value_t = 25)]
frame_rate: u64, frame_rate: u64,
@ -76,8 +79,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
.take() .take()
.ok_or("opening app process stdout failed")?; .ok_or("opening app process stdout failed")?;
// TODO support also RGBW let colors = if cli.white { 4 } else { 3 };
let colors = 3;
// TODO check for overflow and excessive size // TODO check for overflow and excessive size
let buffer_size = cli.cols * cli.rows * colors; let buffer_size = cli.cols * cli.rows * colors;
let mut frame_count = 0; let mut frame_count = 0;
@ -144,10 +146,23 @@ fn main() -> Result<(), Box<dyn error::Error>> {
for y in 0..y_size { for y in 0..y_size {
for x in 0..x_size { for x in 0..x_size {
let i = colors * (y * x_size + x); let i = colors * (y * x_size + x);
let color = if colors == 3 {
let r = f32::from(buffer.frame[i + 0]) / 255.0; let r = f32::from(buffer.frame[i + 0]) / 255.0;
let g = f32::from(buffer.frame[i + 1]) / 255.0; let g = f32::from(buffer.frame[i + 1]) / 255.0;
let b = f32::from(buffer.frame[i + 2]) / 255.0; let b = f32::from(buffer.frame[i + 2]) / 255.0;
let color = [r, g, b, 1.0]; [r, g, b, 1.0]
} else {
let r = f32::from(buffer.frame[i + 0]) / 255.0;
let g = f32::from(buffer.frame[i + 1]) / 255.0;
let b = f32::from(buffer.frame[i + 2]) / 255.0;
let w = f32::from(buffer.frame[i + 3]) / 255.0;
[
(0.5 * r + 0.8 * w).min(1.0),
(0.5 * g + 0.7 * w).min(1.0),
(0.5 * b + 0.6 * w).min(1.0),
1.0,
]
};
let rectangle = [(x as f64) * cs, (y as f64) * cs, cs, cs]; let rectangle = [(x as f64) * cs, (y as f64) * cs, cs, cs];
pw::rectangle(color, rectangle, context.transform, graphics); pw::rectangle(color, rectangle, context.transform, graphics);
} }