Add RGBW support
This commit is contained in:
parent
534ddba827
commit
a6e654f4be
27
src/main.rs
27
src/main.rs
@ -27,6 +27,9 @@ struct Cli {
|
||||
rows: usize,
|
||||
/// Free-format arguments to pass to the executable
|
||||
args: Vec<String>,
|
||||
/// Use RGBW pixel format
|
||||
#[arg(short, long, action = clap::ArgAction::SetTrue)]
|
||||
white: bool,
|
||||
/// Frame rate for displaying
|
||||
#[arg(short, long, default_value_t = 25)]
|
||||
frame_rate: u64,
|
||||
@ -76,8 +79,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||
.take()
|
||||
.ok_or("opening app process stdout failed")?;
|
||||
|
||||
// TODO support also RGBW
|
||||
let colors = 3;
|
||||
let colors = if cli.white { 4 } else { 3 };
|
||||
// TODO check for overflow and excessive size
|
||||
let buffer_size = cli.cols * cli.rows * colors;
|
||||
let mut frame_count = 0;
|
||||
@ -144,10 +146,23 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||
for y in 0..y_size {
|
||||
for x in 0..x_size {
|
||||
let i = colors * (y * x_size + x);
|
||||
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 color = [r, g, b, 1.0];
|
||||
let color = if colors == 3 {
|
||||
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;
|
||||
[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];
|
||||
pw::rectangle(color, rectangle, context.transform, graphics);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user