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.
#[derive(Debug)]
pub struct DitheredImage {
buf: ImageBuffer<Luma<u8>, Vec<u8>>,
palette: Vec<Srgb>,
pub buf: ImageBuffer<Luma<u8>, Vec<u8>>,
pub palette: Vec<Srgb>,
}
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]