pi-frame-server/src/main.rs
2024-07-18 07:34:28 -05:00

53 lines
1.2 KiB
Rust

#[cfg(feature = "eink")]
pub mod display;
pub mod imageproc;
pub mod api;
use crate::display::Wrapper;
use crate::imageproc::{DiffusionMatrix, Ditherer, EInkImage, ErrorDiffusionDither};
use clap::{Parser, Subcommand};
use image::RgbImage;
/// Display images over
#[derive(Debug, Parser)]
#[command(version, about)]
struct Cli {
#[command(subcommand)]
command: Command,
}
#[derive(Debug, Subcommand)]
enum Command {
/// Load a single image
Show,
/// Display a test pattern
Test,
/// Start the HTTP server
Serve,
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
println!("CLI {cli:?}");
if matches!(cli.command, Command::Show) {
let img: RgbImage = image::io::Reader::open("myimage.png")?.decode()?.into();
let mut display = Wrapper::new()?;
let mut eink_buf = EInkImage::new(800, 480);
let dither = ErrorDiffusionDither::new(DiffusionMatrix::Atkinson);
dither.dither(&img, &mut eink_buf);
let raw_buf = eink_buf.into_display_buffer();
display.display(&raw_buf)?;
}
if matches!(cli.command, Command::Test) {
let mut display = Wrapper::new()?;
display.test()?;
}
Ok(())
}