Print images lighter

This commit is contained in:
Joscha 2024-03-15 22:13:45 +01:00
parent e7d3d2b638
commit 9d4ecaaf72
2 changed files with 25 additions and 13 deletions

View file

@ -3,7 +3,7 @@ use image::{
RgbaImage,
};
use mark::dither::{AlgoFloydSteinberg, AlgoStucki, Algorithm, DiffEuclid, Palette};
use palette::{IntoColor, Srgb, Srgba};
use palette::{IntoColor, LinSrgb, Srgba};
use taffy::prelude::{AvailableSpace, Layout, Size};
use crate::Widget;
@ -15,12 +15,12 @@ pub enum DitherAlgorithm {
}
impl DitherAlgorithm {
fn dither(self, image: RgbaImage, palette: &Palette<Srgb>) -> RgbaImage {
fn dither(self, image: RgbaImage, palette: &Palette<LinSrgb>) -> RgbaImage {
match self {
Self::FloydSteinberg => {
<AlgoFloydSteinberg as Algorithm<Srgb, DiffEuclid>>::run(image, palette)
<AlgoFloydSteinberg as Algorithm<LinSrgb, DiffEuclid>>::run(image, palette)
}
Self::Stucki => <AlgoStucki as Algorithm<Srgb, DiffEuclid>>::run(image, palette),
Self::Stucki => <AlgoStucki as Algorithm<LinSrgb, DiffEuclid>>::run(image, palette),
}
}
}
@ -31,11 +31,7 @@ pub struct Image {
grow: bool,
filter: FilterType,
// The palette uses Srgb instead of LinSrgb because dithering in Srgb
// produces better results when printed, even though color distance
// calculations are objectively wrong. Maybe the printer's black ink
// behaviour makes them correct again.
dither_palette: Option<Palette<Srgb>>,
dither_palette: Option<Palette<LinSrgb>>,
dither_algorithm: DitherAlgorithm,
}
@ -70,7 +66,7 @@ impl Image {
let palette = palette
.iter()
.map(|c| c.color.into_color())
.collect::<Vec<Srgb>>();
.collect::<Vec<LinSrgb>>();
self.dither_palette = Some(Palette::new(palette));
self