add cutoff grayscale

This commit is contained in:
devdesk 2024-02-19 22:02:27 +02:00
parent 2347158093
commit 0af76ed532

View File

@ -11,6 +11,8 @@ struct Args {
temperature: bool,
#[arg(short, long, default_value = "/dev/video0")]
device: String,
#[arg(short, long)]
red_cutoff: Option<f64>,
}
fn pixel_to_celcius(x: u16) -> u16 {
@ -96,6 +98,13 @@ fn main() -> anyhow::Result<()> {
let mut pixel = u16::from_be_bytes([frame[i * 2], frame[i * 2 + 1]]);
if args.temperature {
pixel = pixel_to_celcius(pixel);
if let Some(cutoff) = args.red_cutoff {
pixel = if pixel > (256.0 * cutoff) as u16 {
50000
} else {
0
}
}
}
let pixel_swapped = pixel.to_le_bytes();
swapped[i * 2..i * 2 + 2].copy_from_slice(&pixel_swapped);