use crate::rgb::Bgr;
pub type Bgr888 = Bgr<u8>;
impl Bgr888 {
#[must_use]
pub const fn new(packed: u32) -> Self {
let b = ((packed >> 16) & 0xFF) as u8;
let g = ((packed >> 8) & 0xFF) as u8;
let r = (packed & 0xFF) as u8;
Self::from_bgr(b, g, r)
}
}
impl From<[u8; 3]> for Bgr888 {
fn from([b, g, r]: [u8; 3]) -> Self {
Self::from_bgr(b, g, r)
}
}
impl From<Bgr888> for [u8; 3] {
fn from(color: Bgr888) -> Self {
use crate::rgb::{HasBlue, HasGreen, HasRed};
[color.blue(), color.green(), color.red()]
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_bgr888_new() {
assert_eq!(Bgr888::new(0x0000_00FF), Bgr888::from_bgr(0, 0, 255));
assert_eq!(Bgr888::new(0x0000_FF00), Bgr888::from_bgr(0, 255, 0));
assert_eq!(Bgr888::new(0x00FF_0000), Bgr888::from_bgr(255, 0, 0));
}
}