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;