cleanup, add make_image for einkbuffer (wip)
This commit is contained in:
parent
060a6b432e
commit
a9e6f69f34
|
@ -2,6 +2,7 @@ use image::RgbImage;
|
||||||
|
|
||||||
use palette::color_difference::{Ciede2000, EuclideanDistance};
|
use palette::color_difference::{Ciede2000, EuclideanDistance};
|
||||||
use palette::{cast::FromComponents, IntoColor, Lab, Oklch, Srgb};
|
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.
|
/// 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];
|
let v = vec![DisplayColor::Black; width * height];
|
||||||
Self(v)
|
Self(v)
|
||||||
}
|
}
|
||||||
// pub fn make_image(&self) -> RgbImage {
|
pub fn make_image(&self) -> RgbImage {
|
||||||
// RgbImage::from_fn(800, 480, |x, y| {
|
RgbImage::from_fn(800, 480, |x, y| {
|
||||||
// let srgb = Srgb::from(self.0[y * 800 + x]);
|
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<u8> {
|
|
||||||
// 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 {
|
pub trait Ditherer {
|
||||||
fn dither(&self, img: &RgbImage, output: &mut EInkBuffer);
|
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
|
/// ``DiffusionPoint`` is part of the diffusion matrix, represented by a shift in x and y and an error
|
||||||
/// scaling factor.
|
/// scaling factor.
|
||||||
struct DiffusionPoint {
|
struct DiffusionPoint {
|
||||||
|
|
19
src/main.rs
19
src/main.rs
|
@ -3,7 +3,7 @@ pub mod display;
|
||||||
pub mod imageproc;
|
pub mod imageproc;
|
||||||
|
|
||||||
use crate::display::Wrapper;
|
use crate::display::Wrapper;
|
||||||
use crate::imageproc::{DiffusionMatrix, EInkBuffer, ErrorDiffusionDither, Ditherer};
|
use crate::imageproc::{DiffusionMatrix, Ditherer, EInkBuffer, ErrorDiffusionDither};
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
use image::RgbImage;
|
use image::RgbImage;
|
||||||
|
|
||||||
|
@ -21,10 +21,8 @@ enum Command {
|
||||||
Show,
|
Show,
|
||||||
/// Display a test pattern
|
/// Display a test pattern
|
||||||
Test,
|
Test,
|
||||||
/// Start the HTTP sever
|
/// Start the HTTP server
|
||||||
Serve,
|
Serve,
|
||||||
/// Convert an image and save it.
|
|
||||||
Convert,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
|
@ -41,7 +39,6 @@ fn main() -> anyhow::Result<()> {
|
||||||
dither.dither(&img, &mut eink_buf);
|
dither.dither(&img, &mut eink_buf);
|
||||||
let raw_buf = eink_buf.into_display_buffer();
|
let raw_buf = eink_buf.into_display_buffer();
|
||||||
display.display(&raw_buf)?;
|
display.display(&raw_buf)?;
|
||||||
|
|
||||||
}
|
}
|
||||||
if matches!(cli.command, Command::Test) {
|
if matches!(cli.command, Command::Test) {
|
||||||
let mut display = Wrapper::new()?;
|
let mut display = Wrapper::new()?;
|
||||||
|
@ -49,17 +46,5 @@ fn main() -> anyhow::Result<()> {
|
||||||
display.test()?;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue