diff --git a/src/imageproc.rs b/src/imageproc.rs index e39d3d7..d5ea99c 100644 --- a/src/imageproc.rs +++ b/src/imageproc.rs @@ -2,6 +2,7 @@ use image::RgbImage; use palette::color_difference::{Ciede2000, EuclideanDistance}; use palette::{cast::FromComponents, IntoColor, Lab, Oklch, Srgb}; +use image::Rgb as imgRgb; /// Palette used on the display; pixels can be one of these colors. /// @@ -80,35 +81,15 @@ impl EInkBuffer { let v = vec![DisplayColor::Black; width * height]; Self(v) } - // pub fn make_image(&self) -> RgbImage { - // RgbImage::from_fn(800, 480, |x, y| { - // let srgb = Srgb::from(self.0[y * 800 + x]); - // }) - // } + pub fn make_image(&self) -> RgbImage { + RgbImage::from_fn(800, 480, |x, y| { + let srgb = Srgb::from(self.0[(y * 800 + x) as usize]); + let arr: [u8; 3] = srgb.into_format().into(); + imgRgb(arr) + }) + } } -// impl EInkBuffer { -// /// Converts the EInkBuffer into data that can be sent over the SPI API -// /// Bin-packs the two 4-bit colors into bytes. -// pub fn into_buffer(&self) -> Vec { -// vec![] -// } -// -// pub fn new(width: usize, height: usize) -> EInkBuffer { -// EInkBuffer { -// data: vec![DisplayColor::Black; width * height], -// width, -// height, -// } -// } -// pub fn set(&mut self, x: usize, y: usize, value: DisplayColor) { -// self.data[x + y * self.width] = value; -// } -// pub fn get(&self, x:usize, y:usize) -> DisplayColor { -// self.data[x -// } -// } - pub trait Ditherer { fn dither(&self, img: &RgbImage, output: &mut EInkBuffer); } @@ -164,7 +145,6 @@ fn get_error_adjusted(orig: &Lab, err: &Lab, scalar: f32) -> Lab { )) } - /// ``DiffusionPoint`` is part of the diffusion matrix, represented by a shift in x and y and an error /// scaling factor. struct DiffusionPoint { diff --git a/src/main.rs b/src/main.rs index 7cf56bb..8b7dd8c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ pub mod display; pub mod imageproc; use crate::display::Wrapper; -use crate::imageproc::{DiffusionMatrix, EInkBuffer, ErrorDiffusionDither, Ditherer}; +use crate::imageproc::{DiffusionMatrix, Ditherer, EInkBuffer, ErrorDiffusionDither}; use clap::{Parser, Subcommand}; use image::RgbImage; @@ -21,10 +21,8 @@ enum Command { Show, /// Display a test pattern Test, - /// Start the HTTP sever + /// Start the HTTP server Serve, - /// Convert an image and save it. - Convert, } fn main() -> anyhow::Result<()> { @@ -41,7 +39,6 @@ fn main() -> anyhow::Result<()> { 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()?; @@ -49,17 +46,5 @@ fn main() -> anyhow::Result<()> { 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); - - dither.dither(&img, &mut eink_buf); - let raw_buf = eink_buf.into_display_buffer(); - - } - - - Ok(()) }