switch to atkinson dithering
This commit is contained in:
parent
dd148f07a2
commit
8417562e31
6
build.sh
6
build.sh
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set +x
|
set +x
|
||||||
cross build --target aarch64-unknown-linux-gnu --release
|
cross build --target aarch64-unknown-linux-gnu --release --features eink
|
||||||
rsync -aczP target/aarch64-unknown-linux-gnu/release/pi-frame-server 192.168.0.186:
|
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:
|
# 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
|
||||||
|
|
|
@ -141,7 +141,7 @@ pub fn nearest_neighbor(input_color: Lab) -> (DisplayColor, Lab) {
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(idx, p_color)| {
|
.map(|(idx, p_color)| {
|
||||||
let c: Lab = (*p_color).into_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))
|
.min_by(|(_, a, _), (_, b, _)| a.total_cmp(b))
|
||||||
.expect("could not find a color");
|
.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(0, 1, 5.0 / 16.0),
|
||||||
DiffusionPoint::new(1, 1, 1.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 {
|
impl Ditherer for FloydSteinbergDither {
|
||||||
fn dither(&mut self, img: &RgbImage, output: &mut EInkBuffer) {
|
fn dither(&mut self, img: &RgbImage, output: &mut EInkBuffer) {
|
||||||
|
@ -227,7 +235,7 @@ impl Ditherer for FloydSteinbergDither {
|
||||||
// set the color in the output buffer.
|
// set the color in the output buffer.
|
||||||
output.0[index] = nearest;
|
output.0[index] = nearest;
|
||||||
// take the error, and propagate it.
|
// 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 {
|
let Some(target_x) = x.checked_add_signed(point.xshift) else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
|
@ -36,7 +36,7 @@ fn main() -> anyhow::Result<()> {
|
||||||
let mut display = Wrapper::new()?;
|
let mut display = Wrapper::new()?;
|
||||||
|
|
||||||
let mut eink_buf = EInkBuffer::new(800, 480);
|
let mut eink_buf = EInkBuffer::new(800, 480);
|
||||||
let mut dither = NNDither{};
|
let mut dither = FloydSteinbergDither{};
|
||||||
|
|
||||||
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();
|
||||||
|
|
Loading…
Reference in a new issue