pi-frame-server/src/main.rs

66 lines
1.6 KiB
Rust
Raw Normal View History

2024-07-16 23:55:59 +00:00
#[cfg(feature = "eink")]
2024-07-02 15:57:29 +00:00
pub mod display;
2024-06-29 16:55:37 +00:00
pub mod imageproc;
2024-07-16 23:55:59 +00:00
use crate::display::Wrapper;
use crate::imageproc::{DiffusionMatrix, EInkBuffer, ErrorDiffusionDither, Ditherer};
2024-07-02 15:57:29 +00:00
use clap::{Parser, Subcommand};
use image::RgbImage;
/// Display images over
2024-06-29 16:55:37 +00:00
#[derive(Debug, Parser)]
#[command(version, about)]
struct Cli {
#[command(subcommand)]
command: Command,
}
#[derive(Debug, Subcommand)]
enum Command {
/// Load a single image
2024-07-02 15:57:29 +00:00
Show,
2024-07-17 05:24:11 +00:00
/// Display a test pattern
Test,
2024-06-29 16:55:37 +00:00
/// Start the HTTP sever
Serve,
2024-07-17 05:24:11 +00:00
/// Convert an image and save it.
Convert,
2024-06-29 16:55:37 +00:00
}
fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
println!("CLI {cli:?}");
2024-07-17 05:24:11 +00:00
if matches!(cli.command, Command::Show) {
2024-07-02 15:57:29 +00:00
let img: RgbImage = image::io::Reader::open("myimage.png")?.decode()?.into();
2024-07-16 23:55:59 +00:00
let mut display = Wrapper::new()?;
2024-07-02 15:57:29 +00:00
let mut eink_buf = EInkBuffer::new(800, 480);
let dither = ErrorDiffusionDither::new(DiffusionMatrix::Atkinson);
2024-07-02 15:57:29 +00:00
dither.dither(&img, &mut eink_buf);
let raw_buf = eink_buf.into_display_buffer();
display.display(&raw_buf)?;
2024-07-17 05:24:11 +00:00
}
if matches!(cli.command, Command::Test) {
let mut display = Wrapper::new()?;
display.test()?;
}
if matches!(cli.command, Command::Convert) {
let img: RgbImage = image::io::Reader::open("myimage.png")?.decode()?.into();
let mut eink_buf = EInkBuffer::new(800, 480);
let dither = ErrorDiffusionDither::new(DiffusionMatrix::Atkinson);
2024-07-17 05:24:11 +00:00
dither.dither(&img, &mut eink_buf);
let raw_buf = eink_buf.into_display_buffer();
2024-06-29 16:55:37 +00:00
}
2024-07-17 05:24:11 +00:00
2024-06-29 16:55:37 +00:00
Ok(())
2024-06-24 13:29:59 +00:00
}