From 57e784c6e962b358b4c1bd088bed4594590dcf9f Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Sun, 4 May 2025 16:19:25 +0200 Subject: [PATCH] i didnt say im fancy fixing it there is an off by one somewhere _shrug_ --- src/ledwand_dither.rs | 12 ++++++++++-- src/main.rs | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/ledwand_dither.rs b/src/ledwand_dither.rs index 95ffe02..9f3a634 100644 --- a/src/ledwand_dither.rs +++ b/src/ledwand_dither.rs @@ -1,6 +1,7 @@ //! Based on https://github.com/WarkerAnhaltRanger/CCCB_Ledwand use image::GrayImage; +use log::error; use servicepoint::{Bitmap, DisplayBitVec, PIXEL_HEIGHT}; type GrayHistogram = [usize; 256]; @@ -217,8 +218,15 @@ fn ostromoukhov_dither_pixel( destination.set(position, destination_value); let mut diffuse = |to: usize, mat: i16| { - let diffuse_value = source[to] as i16 + mat; - source[to] = diffuse_value.clamp(u8::MIN.into(), u8::MAX.into()) as u8; + match source.get(to) { + None => { + error!("ostromoukhov_dither_pixel - invalid index {to}"); + } + Some(val) => { + let diffuse_value = *val as i16 + mat; + source[to] = diffuse_value.clamp(u8::MIN.into(), u8::MAX.into()) as u8; + } + }; }; let lookup = if destination_value { diff --git a/src/main.rs b/src/main.rs index a485526..cdae13c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ use crate::{ }; use clap::Parser; use log::debug; -use servicepoint::{Brightness, HardResetCommand, UdpSocketExt}; +use servicepoint::{Brightness, HardResetCommand}; mod brightness; mod cli;