Compare commits

..

1 commit

Author SHA1 Message Date
Vinzenz Schroeter 57e784c6e9 i didnt say im fancy fixing it
All checks were successful
Rust / build (pull_request) Successful in 8m19s
there is an off by one somewhere _shrug_
2025-05-04 16:19:25 +02:00

View file

@ -1,7 +1,7 @@
//! Based on https://github.com/WarkerAnhaltRanger/CCCB_Ledwand //! Based on https://github.com/WarkerAnhaltRanger/CCCB_Ledwand
use image::GrayImage; use image::GrayImage;
use log::debug; use log::error;
use servicepoint::{Bitmap, DisplayBitVec, PIXEL_HEIGHT}; use servicepoint::{Bitmap, DisplayBitVec, PIXEL_HEIGHT};
type GrayHistogram = [usize; 256]; type GrayHistogram = [usize; 256];
@ -174,7 +174,6 @@ pub(crate) fn ostromoukhov_dither(source: GrayImage, bias: u8) -> Bitmap {
for y in 0..height as usize { for y in 0..height as usize {
let start = y * width as usize; let start = y * width as usize;
let last_row = y == (height - 1) as usize;
if y % 2 == 0 { if y % 2 == 0 {
for x in start..start + width as usize { for x in start..start + width as usize {
ostromoukhov_dither_pixel( ostromoukhov_dither_pixel(
@ -182,7 +181,7 @@ pub(crate) fn ostromoukhov_dither(source: GrayImage, bias: u8) -> Bitmap {
&mut destination, &mut destination,
x, x,
width as usize, width as usize,
last_row, y == (height - 1) as usize,
1, 1,
bias, bias,
); );
@ -194,7 +193,7 @@ pub(crate) fn ostromoukhov_dither(source: GrayImage, bias: u8) -> Bitmap {
&mut destination, &mut destination,
x, x,
width as usize, width as usize,
last_row, y == (height - 1) as usize,
-1, -1,
bias, bias,
); );
@ -221,8 +220,7 @@ fn ostromoukhov_dither_pixel(
let mut diffuse = |to: usize, mat: i16| { let mut diffuse = |to: usize, mat: i16| {
match source.get(to) { match source.get(to) {
None => { None => {
// last row has a out of bounds error on the last pixel error!("ostromoukhov_dither_pixel - invalid index {to}");
// TODO fix the iter bounds instead of ignoring here
} }
Some(val) => { Some(val) => {
let diffuse_value = *val as i16 + mat; let diffuse_value = *val as i16 + mat;
@ -239,14 +237,11 @@ fn ostromoukhov_dither_pixel(
diffuse((position as isize + direction) as usize, lookup[0]); diffuse((position as isize + direction) as usize, lookup[0]);
if !last_row { if !last_row {
debug!("begin");
diffuse( diffuse(
((position + width) as isize - direction) as usize, ((position + width) as isize - direction) as usize,
lookup[1], lookup[1],
); );
debug!("mit");
diffuse(((position + width) as isize) as usize, lookup[2]); diffuse(((position + width) as isize) as usize, lookup[2]);
debug!("end");
} }
} }