feim 0.25.1

Modular crate for working with images in Rust
Documentation
use super::convert::ConvertFrom;
#[cfg(feature = "col-nrgba")]
use super::Nrgba;
use super::{Color, Zero};
#[cfg(feature = "col-nrgba")]
use crate::specialized;

#[derive(Copy, Clone, Eq, PartialEq, Debug)]
#[repr(C)]
pub struct Rgb {
    pub r: u8,
    pub g: u8,
    pub b: u8,
}

impl Zero for Rgb {
    const ZERO: Self = Rgb { r: 0, g: 0, b: 0 };
}

impl Color for Rgb {
    fn as_rgba(&self) -> (u32, u32, u32, u32) {
        let r = self.r as u32;
        let g = self.g as u32;
        let b = self.b as u32;

        let r = r | (r << 8);
        let g = g | (g << 8);
        let b = b | (b << 8);
        let a = 0xffff;

        (r, g, b, a)
    }
}

impl<C: Color> ConvertFrom<C> for Rgb {
    fn convert_from(c: C) -> Rgb {
        let (r, g, b, _) = c.as_rgba();
        Rgb {
            r: ((r >> 8) & 0xff) as u8,
            g: ((g >> 8) & 0xff) as u8,
            b: ((b >> 8) & 0xff) as u8,
        }
    }
}

#[cfg(feature = "col-nrgba")]
impl ConvertFrom<Nrgba, specialized::For<Rgb>> for Rgb {
    fn convert_from(c: Nrgba) -> Rgb {
        Rgb {
            r: c.r,
            g: c.g,
            b: c.b,
        }
    }
}