From de20da4e8652be889ed49f6d944f9652193f3f4e Mon Sep 17 00:00:00 2001 From: saji Date: Thu, 1 Aug 2024 19:55:12 -0500 Subject: [PATCH] comments, make DitheredImage fields public --- src/dither.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/dither.rs b/src/dither.rs index 33a55ee..7ea316a 100644 --- a/src/dither.rs +++ b/src/dither.rs @@ -39,8 +39,8 @@ pub enum ProcessingError { /// Buffer to be sent to the ``EInk`` display. #[derive(Debug)] pub struct DitheredImage { - buf: ImageBuffer, Vec>, - palette: Vec, + pub buf: ImageBuffer, Vec>, + pub palette: Vec, } impl DitheredImage { @@ -86,8 +86,7 @@ pub trait Ditherer { fn dither(&mut self, img: &RgbImage, output: &mut DitheredImage); } -/// Find the closest approximate palette color to the given sRGB value. -/// This uses euclidian distance in linear space. +/// Find the closest approximate palette color fn nearest_neighbor(input_color: Lab, palette: &[Lab]) -> (u8, Lab) { let (nearest, _, color_diff) = palette .iter() @@ -95,7 +94,7 @@ fn nearest_neighbor(input_color: Lab, palette: &[Lab]) -> (u8, Lab) { .map(|(idx, p_color)| { ( idx, - input_color.difference(*p_color), + input_color.difference(*p_color), // this is CIEDIE2000 based and highly accurate. input_color - *p_color, ) }) @@ -199,7 +198,7 @@ static STUKI_DITHER_POINTS: &[DiffusionPoint] = &[ pub type DiffusionMatrix<'a> = &'a [DiffusionPoint]; #[derive(Debug)] -pub struct ErrorDiffusion<'a>(&'a [DiffusionPoint]); +pub struct ErrorDiffusion<'a>(DiffusionMatrix<'a>); impl<'a> ErrorDiffusion<'a> { #[must_use]