agb/agb-image-converter/src/colour.rs

18 lines
408 B
Rust
Raw Normal View History

2021-04-20 09:40:07 +10:00
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Colour {
pub r: u8,
pub g: u8,
pub b: u8,
}
impl Colour {
pub fn from_rgb(r: u8, g: u8, b: u8) -> Self {
Colour { r, g, b }
}
2021-04-21 05:41:04 +10:00
pub fn to_rgb15(&self) -> u16 {
let (r, g, b) = (self.r as u16, self.g as u16, self.b as u16);
((r >> 3) & 31) | (((g >> 3) & 31) << 5) | (((b >> 3) & 31) << 10)
}
2021-04-20 09:40:07 +10:00
}