Take palette by ref in Algorithm

This commit is contained in:
Joscha 2024-03-09 22:13:56 +01:00
parent 9464487c57
commit 243ec79f42
2 changed files with 6 additions and 6 deletions

View file

@ -216,7 +216,7 @@ impl DitherCmd {
.map(|c| c.0.into_format().into_color()) .map(|c| c.0.into_format().into_color())
.collect::<Vec<C>>(); .collect::<Vec<C>>();
let palette = Palette::<C>::new(colors); let palette = Palette::<C>::new(colors);
A::run(image, palette) A::run(image, &palette)
} }
} }

View file

@ -108,7 +108,7 @@ impl<C> Palette<C> {
//////////////// ////////////////
pub trait Algorithm<C, D> { pub trait Algorithm<C, D> {
fn run(image: RgbaImage, palette: Palette<C>) -> RgbaImage; fn run(image: RgbaImage, palette: &Palette<C>) -> RgbaImage;
} }
pub struct AlgoThreshold; pub struct AlgoThreshold;
@ -120,7 +120,7 @@ where
C: IntoColor<Srgb>, C: IntoColor<Srgb>,
D: Difference<C>, D: Difference<C>,
{ {
fn run(mut image: RgbaImage, palette: Palette<C>) -> RgbaImage { fn run(mut image: RgbaImage, palette: &Palette<C>) -> RgbaImage {
for pixel in image.pixels_mut() { for pixel in image.pixels_mut() {
let color: C = util::pixel_to_color(*pixel); let color: C = util::pixel_to_color(*pixel);
let color = palette.nearest::<D>(color); let color = palette.nearest::<D>(color);
@ -151,7 +151,7 @@ where
C: IntoColor<Srgb>, C: IntoColor<Srgb>,
D: Difference<C>, D: Difference<C>,
{ {
fn run(mut image: RgbaImage, palette: Palette<C>) -> RgbaImage { fn run(mut image: RgbaImage, palette: &Palette<C>) -> RgbaImage {
let mut rng = SmallRng::seed_from_u64(0); let mut rng = SmallRng::seed_from_u64(0);
let range_radius = 1.0; let range_radius = 1.0;
@ -223,7 +223,7 @@ where
D: Difference<C>, D: Difference<C>,
Srgb: IntoColor<C>, Srgb: IntoColor<C>,
{ {
fn run(mut image: RgbaImage, palette: Palette<C>) -> RgbaImage { fn run(mut image: RgbaImage, palette: &Palette<C>) -> RgbaImage {
for y in 0..image.height() { for y in 0..image.height() {
for x in 0..image.width() { for x in 0..image.width() {
let pixel = image.get_pixel(x, y); let pixel = image.get_pixel(x, y);
@ -253,7 +253,7 @@ where
D: Difference<C>, D: Difference<C>,
Srgb: IntoColor<C>, Srgb: IntoColor<C>,
{ {
fn run(mut image: RgbaImage, palette: Palette<C>) -> RgbaImage { fn run(mut image: RgbaImage, palette: &Palette<C>) -> RgbaImage {
for y in 0..image.height() { for y in 0..image.height() {
for x in 0..image.width() { for x in 0..image.width() {
let pixel = image.get_pixel(x, y); let pixel = image.get_pixel(x, y);