get palette colours by index
This commit is contained in:
parent
dc8fd68e32
commit
c1be226956
|
@ -13,7 +13,24 @@ pub struct Palette {
|
|||
}
|
||||
|
||||
impl Palette {
|
||||
/// todo result
|
||||
/// if trying to get an out-of-bounds index, colours will wrap around
|
||||
/// so if palette has 8 colours (0-7) and index is 8, will return 0
|
||||
pub fn get_colour(&self, index: &u8) -> Option<&Colour> {
|
||||
self.colours.get((index % self.colours.len() as u8) as usize)
|
||||
}
|
||||
|
||||
/// colour 0 is transparent
|
||||
pub fn get_colour_rgba8(&self, index: &u8) -> Vec<u8> {
|
||||
match index {
|
||||
0 => vec![0,0,0,0],
|
||||
_ => {
|
||||
let colour = self.get_colour(index).unwrap();
|
||||
vec![colour.red, colour.green, colour.blue, 255]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// todo Result<Palette>
|
||||
pub fn from_file(path: PathBuf) -> Self {
|
||||
match path.extension().unwrap().to_str().unwrap() {
|
||||
"gpl" => Self::from_gpl(path),
|
||||
|
|
Loading…
Reference in New Issue