pixel 0.1.3

Prototype! Pixel manipulation library (blend and convert colors)
Documentation
pub mod utils;
pub mod rgb;
pub mod hsv;
pub mod hsl;
pub mod bin;
pub mod blending;

pub use super::*;
pub use self::rgb::*;
pub use self::hsv::*;
pub use self::hsl::*;
pub use self::blending::*;

/// Color which can be represented in three major formats: RGB, HSV and HSL
// TODO: Add YUV representation support
pub trait Color: FromColor {
    fn to_rgb(&self) -> RGB;
    fn to_hsv(&self) -> HSV where Self: Sized { let rgb = self.to_rgb(); HSV { hue: utils::get_hue(rgb), saturation: utils::get_hsv_saturation(rgb), value: utils::get_value(rgb) } }
    fn to_hsl(&self) -> HSL where Self: Sized { let rgb = self.to_rgb(); HSL { hue: utils::get_hue(rgb), saturation: utils::get_hsl_saturation(rgb), lightness: utils::get_lightness(rgb) } }

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

    fn get_hue(&self) -> f32 where Self: Sized { self.to_hsl().hue }
    fn get_hsl_saturation(&self) -> f32 where Self: Sized { self.to_hsl().saturation }
    fn get_hsv_saturation(&self) -> f32 where Self: Sized { self.to_hsv().saturation }
    fn get_lightness(&self) -> f32 where Self: Sized { self.to_hsl().lightness }
    fn get_value(&self) -> f32 where Self: Sized { self.to_hsv().value }
}

pub trait Pixel : Color + FromPixel {
    fn to_rgba(&self) -> RGBA { RGBA{ rgb: self.to_rgb(), alpha: self.get_alpha() } }
    fn get_alpha(&self) -> f32 { 1.0 }

    fn blend<RHS: Pixel>(&self, rhs: &RHS, factor: f32, op: BlendMode) -> Self where Self: Copy {
        let blended = alpha_blend(self, rhs, factor, |lhs, rhs| blend(lhs, rhs, op));
        <Self as FromPixel>::from(&blended)
    }
}

pub trait FromColor: Sized {
    fn loosing_color() -> bool { false }
    fn from<C: Color>(color: &C) -> Self;
}

pub trait FromPixel: FromColor {
    fn loosing_alpha() -> bool { true }
    fn from<P: Pixel>(pixel: &P) -> Self { FromColor::from(pixel) }
}