use palette::Srgb;
use crate::{utils::image::RgbPixelRepr, effect::Effect};
use super::raw::{contrast, gradient_map, quantize_hue, brighten, saturate, shift_hue, multiply_hue};
pub struct HueRotate(
pub f32
);
pub struct Contrast(
pub f32
);
pub struct Brighten(
pub f32
);
pub struct Saturate(
)` would mean setting each pixel to `128.0 chroma` in LCH terms -
pub f32
);
pub struct GradientMap {
map: Vec<(Srgb, f32)>
}
impl GradientMap {
pub fn new() -> Self {
Self { map: Vec::new() }
}
pub fn with_map(map: Vec<(Srgb, f32)>) -> Self {
Self { map }
}
pub fn add_entry(&mut self, colour: Srgb, luminance: f32) -> &mut Self {
self.map.push((colour, luminance));
self
}
}
pub struct QuantizeHue {
hues: Vec<f32>
}
impl QuantizeHue {
pub fn new() -> Self {
Self { hues: Vec::new() }
}
pub fn with_hues(hues: Vec<f32>) -> Self {
Self { hues }
}
pub fn add_hue(&mut self, hue: f32) -> &mut Self {
self.hues.push(hue);
self
}
}
pub struct MultiplyHue(pub f32);
impl Effect<RgbPixelRepr> for HueRotate {
fn affect(&self, item: RgbPixelRepr) -> RgbPixelRepr {
shift_hue(item, self.0)
}
}
impl Effect<RgbPixelRepr> for Contrast {
fn affect(&self, item: RgbPixelRepr) -> RgbPixelRepr {
contrast(item, self.0)
}
}
impl Effect<RgbPixelRepr> for Brighten {
fn affect(&self, item: RgbPixelRepr) -> RgbPixelRepr {
brighten(item, self.0)
}
}
impl Effect<RgbPixelRepr> for Saturate {
fn affect(&self, item: RgbPixelRepr) -> RgbPixelRepr {
saturate(item, self.0)
}
}
impl Effect<RgbPixelRepr> for QuantizeHue {
fn affect(&self, item: RgbPixelRepr) -> RgbPixelRepr {
quantize_hue(item, &self.hues)
}
}
impl Effect<RgbPixelRepr> for GradientMap {
fn affect(&self, item: RgbPixelRepr) -> RgbPixelRepr {
gradient_map(item, &self.map).map_or(item, |colour| colour.into_format().into())
}
}
impl Effect<RgbPixelRepr> for MultiplyHue {
fn affect(&self, item: RgbPixelRepr) -> RgbPixelRepr {
multiply_hue(item, self.0)
}
}