comments, make DitheredImage fields public

This commit is contained in:
saji 2024-08-01 19:55:12 -05:00
parent 35ef64a829
commit de20da4e86

View file

@ -39,8 +39,8 @@ pub enum ProcessingError {
/// Buffer to be sent to the ``EInk`` display. /// Buffer to be sent to the ``EInk`` display.
#[derive(Debug)] #[derive(Debug)]
pub struct DitheredImage { pub struct DitheredImage {
buf: ImageBuffer<Luma<u8>, Vec<u8>>, pub buf: ImageBuffer<Luma<u8>, Vec<u8>>,
palette: Vec<Srgb>, pub palette: Vec<Srgb>,
} }
impl DitheredImage { impl DitheredImage {
@ -86,8 +86,7 @@ pub trait Ditherer {
fn dither(&mut self, img: &RgbImage, output: &mut DitheredImage); fn dither(&mut self, img: &RgbImage, output: &mut DitheredImage);
} }
/// Find the closest approximate palette color to the given sRGB value. /// Find the closest approximate palette color
/// This uses euclidian distance in linear space.
fn nearest_neighbor(input_color: Lab, palette: &[Lab]) -> (u8, Lab) { fn nearest_neighbor(input_color: Lab, palette: &[Lab]) -> (u8, Lab) {
let (nearest, _, color_diff) = palette let (nearest, _, color_diff) = palette
.iter() .iter()
@ -95,7 +94,7 @@ fn nearest_neighbor(input_color: Lab, palette: &[Lab]) -> (u8, Lab) {
.map(|(idx, p_color)| { .map(|(idx, p_color)| {
( (
idx, idx,
input_color.difference(*p_color), input_color.difference(*p_color), // this is CIEDIE2000 based and highly accurate.
input_color - *p_color, input_color - *p_color,
) )
}) })
@ -199,7 +198,7 @@ static STUKI_DITHER_POINTS: &[DiffusionPoint] = &[
pub type DiffusionMatrix<'a> = &'a [DiffusionPoint]; pub type DiffusionMatrix<'a> = &'a [DiffusionPoint];
#[derive(Debug)] #[derive(Debug)]
pub struct ErrorDiffusion<'a>(&'a [DiffusionPoint]); pub struct ErrorDiffusion<'a>(DiffusionMatrix<'a>);
impl<'a> ErrorDiffusion<'a> { impl<'a> ErrorDiffusion<'a> {
#[must_use] #[must_use]