pixel 0.1.3

Prototype! Pixel manipulation library (blend and convert colors)
Documentation
use super::*;
use super::utils::*;

#[derive(Clone)]
#[derive(Copy)]
pub struct RGB {
    pub red: f32,
    pub green: f32,
    pub blue: f32
}

impl RGB {
    pub fn new(red: f32, green: f32, blue: f32) -> RGB { RGB{red: red, green: green, blue: blue} }
}

impl Color for RGB {
    fn to_rgb(&self) -> RGB { *self }
    fn to_hsv(&self) -> HSV { HSV { hue: get_hue(*self), saturation: get_hsv_saturation(*self), value: get_value(*self) } }
    fn to_hsl(&self) -> HSL { HSL { hue: get_hue(*self), saturation: get_hsl_saturation(*self), lightness: get_lightness(*self) } }

    fn get_red(&self) -> f32 { self.red }
    fn get_green(&self) -> f32 { self.green }
    fn get_blue(&self) -> f32 { self.blue }

    fn get_hue(&self) -> f32 { utils::get_hue(*self) }
    fn get_hsl_saturation(&self) -> f32 { utils::get_hsl_saturation(*self) }
    fn get_hsv_saturation(&self) -> f32 { utils::get_hsv_saturation(*self) }
    fn get_lightness(&self) -> f32 { utils::get_lightness(*self) }
    fn get_value(&self) -> f32 { utils::get_value(*self) }
}

impl Pixel for RGB {}

impl FromPixel for RGB {}

impl FromColor for RGB {
    fn from<C: Color>(color: &C) -> RGB { color.to_rgb() }
}

#[derive(Clone)]
#[derive(Copy)]
pub struct RGBA {
    pub rgb: RGB,
    pub alpha: f32
}

impl Color for RGBA {
    fn to_rgb(&self) -> RGB { self.rgb }

    fn get_red(&self) -> f32 { self.rgb.red }
    fn get_green(&self) -> f32 { self.rgb.green }
    fn get_blue(&self) -> f32 { self.rgb.blue }

    fn get_hue(&self) -> f32 { utils::get_hue(self.rgb) }
    fn get_hsl_saturation(&self) -> f32 { utils::get_hsl_saturation(self.rgb) }
    fn get_hsv_saturation(&self) -> f32 { utils::get_hsv_saturation(self.rgb) }
    fn get_lightness(&self) -> f32 { utils::get_lightness(self.rgb) }
    fn get_value(&self) -> f32 { utils::get_value(self.rgb) }
}

impl Pixel for RGBA {
    fn to_rgba(&self) -> RGBA { *self }
    fn get_alpha(&self) -> f32 { self.alpha }
}

impl FromColor for RGBA {
    fn from<C: Color>(color: &C) -> RGBA { RGBA{ rgb: color.to_rgb(), alpha: 1.0 } }
}

impl FromPixel for RGBA {
    fn loosing_alpha() -> bool { false }
    fn from<P: Pixel>(pixel: &P) -> RGBA { RGBA{ rgb: pixel.to_rgb(), alpha: pixel.get_alpha() } }
}