#[derive(Clone, Copy)]
pub struct Rgb565(u16);
impl Rgb565 {
pub const fn new(r: u8, g: u8, b: u8) -> Rgb565 {
let r = (r as u16 >> 3) & 0x1F;
let g = (g as u16 >> 2) & 0x3F;
let b = (b as u16 >> 3) & 0x1F;
Rgb565((r << 11) | (g << 5) | b)
}
pub const fn get_raw_color(&self) -> u16 {
self.0
}
pub const fn black() -> Self {
Self(0)
}
pub const fn red() -> Self {
Self(0xF800)
}
pub const fn green() -> Self {
Self(0x07E0)
}
pub const fn blue() -> Self {
Self(0x001F)
}
pub const fn white() -> Self {
Self(0xFFFF)
}
pub const fn yellow() -> Self {
Self(0xFFE0)
}
pub const fn cyan() -> Self {
Self(0x07FF)
}
pub const fn magenta() -> Self {
Self(0xF81F)
}
pub const fn non_zero(&self) -> bool {
self.0 != 0
}
pub const fn to_1bit(&self) -> (bool, bool, bool) {
let r = (self.0 >> 11) & 0x1F != 0;
let g = (self.0 >> 5) & 0x3F != 0;
let b = self.0 & 0x1F != 0;
(r, g, b)
}
}