make lab conversion parallel; use hyab
This commit is contained in:
parent
d47a08587c
commit
8816176ca7
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1463,6 +1463,7 @@ dependencies = [
|
||||||
"mime",
|
"mime",
|
||||||
"minijinja",
|
"minijinja",
|
||||||
"palette",
|
"palette",
|
||||||
|
"rayon",
|
||||||
"rusqlite",
|
"rusqlite",
|
||||||
"serde",
|
"serde",
|
||||||
"strum",
|
"strum",
|
||||||
|
|
|
@ -16,6 +16,7 @@ linux-embedded-hal = { version = "0.4.0"}
|
||||||
mime = "0.3.17"
|
mime = "0.3.17"
|
||||||
minijinja = "2.1.0"
|
minijinja = "2.1.0"
|
||||||
palette = "0.7.6"
|
palette = "0.7.6"
|
||||||
|
rayon = "1.10.0"
|
||||||
rusqlite = { version = "0.32.1", features = ["bundled"] }
|
rusqlite = { version = "0.32.1", features = ["bundled"] }
|
||||||
serde = { version = "1.0.204", features = ["derive"] }
|
serde = { version = "1.0.204", features = ["derive"] }
|
||||||
strum = { version = "0.26.3", features = ["derive"] }
|
strum = { version = "0.26.3", features = ["derive"] }
|
||||||
|
|
|
@ -6,6 +6,7 @@ use tracing::instrument;
|
||||||
use image::Rgb as imgRgb;
|
use image::Rgb as imgRgb;
|
||||||
use palette::color_difference::{Ciede2000, HyAb};
|
use palette::color_difference::{Ciede2000, HyAb};
|
||||||
use palette::{cast::FromComponents, IntoColor, Lab, Srgb};
|
use palette::{cast::FromComponents, IntoColor, Lab, Srgb};
|
||||||
|
use rayon::prelude::*;
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
strum::EnumString, strum::Display, Serialize, Deserialize, PartialEq, Eq, Debug, Clone,
|
strum::EnumString, strum::Display, Serialize, Deserialize, PartialEq, Eq, Debug, Clone,
|
||||||
|
@ -94,7 +95,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), // this is CIEDIE2000 based and highly accurate.
|
input_color.hybrid_distance(*p_color), // this is CIEDIE2000 based and highly accurate.
|
||||||
input_color - *p_color,
|
input_color - *p_color,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -214,11 +215,9 @@ impl<'a> Ditherer for ErrorDiffusion<'a> {
|
||||||
// first, a view into the rgb components
|
// first, a view into the rgb components
|
||||||
let srgb = <&[Srgb<u8>]>::from_components(&**img);
|
let srgb = <&[Srgb<u8>]>::from_components(&**img);
|
||||||
let (xsize, ysize) = img.dimensions();
|
let (xsize, ysize) = img.dimensions();
|
||||||
// our destination buffer.
|
// our temporary buffer. we push the error here.
|
||||||
let mut temp_img: Vec<Lab> = Vec::with_capacity((xsize * ysize) as usize);
|
let mut temp_img: Vec<Lab> = srgb.par_iter().map(|p| p.into_format().into_color()).collect();
|
||||||
for pix in srgb {
|
|
||||||
temp_img.push(pix.into_format().into_color());
|
|
||||||
}
|
|
||||||
let lab_palette: Vec<Lab> = output.palette.iter().map(|c| Lab::from_color(*c)).collect();
|
let lab_palette: Vec<Lab> = output.palette.iter().map(|c| Lab::from_color(*c)).collect();
|
||||||
|
|
||||||
// TODO: rework this to make more sense.
|
// TODO: rework this to make more sense.
|
||||||
|
|
Loading…
Reference in a new issue