1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
use super::{grayscale, Hsl, Rgb}; use crate::{consts, ColorTransform, SaturationInSpace}; use consts::RGB_UNIT_MAX; impl ColorTransform for Rgb { fn lighten(&mut self, amt: f64) { let mut hsl: Hsl = self.into(); hsl.lighten(amt); let lightened_rgb: Rgb = hsl.as_ref().into(); self._apply_tuple(&lightened_rgb.into()); } fn saturate(&mut self, sat: SaturationInSpace) { match sat { SaturationInSpace::Hsl(amt) => { let mut hsl: Hsl = self.into(); hsl.set_saturation(hsl.get_saturation() + amt); let new_rgb = Rgb::from(hsl); self._apply_tuple(&new_rgb.into()); } SaturationInSpace::Hsv(amt) => { println!("{}", amt); unimplemented!(); } } } fn adjust_hue(&mut self, hue: f64) { let mut hsl: Hsl = self.into(); hsl.adjust_hue(hue); self._apply_tuple(&Rgb::from(hsl).into()); } fn grayscale_simple(&mut self) { grayscale::rgb_grayscale(self, grayscale::GrayScaleMethod::AverageProminent); } fn invert(&mut self) { self.r = RGB_UNIT_MAX - self.r; self.g = RGB_UNIT_MAX - self.g; self.b = RGB_UNIT_MAX - self.b; } }