switch to atkinson dithering

This commit is contained in:
saji 2024-07-17 10:20:06 -05:00
parent dd148f07a2
commit 8417562e31
3 changed files with 14 additions and 6 deletions

View file

@ -1,6 +1,6 @@
#!/bin/bash
set +x
cross build --target aarch64-unknown-linux-gnu --release
rsync -aczP target/aarch64-unknown-linux-gnu/release/pi-frame-server 192.168.0.186:
cross build --target aarch64-unknown-linux-gnu --release --features eink
rsync -aczP target/aarch64-unknown-linux-gnu/release/pi-frame-server 192.168.0.185:
# scp target/aarch64-unknown-linux-gnu/debug/pi-frame-server 192.168.0.186:
ssh 192.168.0.186 ./pi-frame-server load
ssh 192.168.0.185 ./pi-frame-server show

View file

@ -141,7 +141,7 @@ pub fn nearest_neighbor(input_color: Lab) -> (DisplayColor, Lab) {
.enumerate()
.map(|(idx, p_color)| {
let c: Lab = (*p_color).into_color();
(idx, input_color.distance_squared(c), input_color - c)
(idx, input_color.difference(c), input_color - c)
})
.min_by(|(_, a, _), (_, b, _)| a.total_cmp(b))
.expect("could not find a color");
@ -207,6 +207,14 @@ const FLOYD_STEINBERG: [DiffusionPoint; 4] = [
DiffusionPoint::new(0, 1, 5.0 / 16.0),
DiffusionPoint::new(1, 1, 1.0 / 16.0),
];
const ATKINSON_DITHER: [DiffusionPoint; 6] = [
DiffusionPoint::new(1, 0, 1.0/8.0),
DiffusionPoint::new(2, 0, 1.0/8.0),
DiffusionPoint::new(-1, 1, 1.0/8.0),
DiffusionPoint::new(0, 1, 1.0/8.0),
DiffusionPoint::new(1, 1, 1.0/8.0),
DiffusionPoint::new(0, 2, 1.0/8.0),
];
impl Ditherer for FloydSteinbergDither {
fn dither(&mut self, img: &RgbImage, output: &mut EInkBuffer) {
@ -227,7 +235,7 @@ impl Ditherer for FloydSteinbergDither {
// set the color in the output buffer.
output.0[index] = nearest;
// take the error, and propagate it.
for point in FLOYD_STEINBERG {
for point in ATKINSON_DITHER {
let Some(target_x) = x.checked_add_signed(point.xshift) else {
continue;
};

View file

@ -36,7 +36,7 @@ fn main() -> anyhow::Result<()> {
let mut display = Wrapper::new()?;
let mut eink_buf = EInkBuffer::new(800, 480);
let mut dither = NNDither{};
let mut dither = FloydSteinbergDither{};
dither.dither(&img, &mut eink_buf);
let raw_buf = eink_buf.into_display_buffer();