diff --git a/src/palette.rs b/src/palette.rs index 73b548f..37704f5 100644 --- a/src/palette.rs +++ b/src/palette.rs @@ -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 { + 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 pub fn from_file(path: PathBuf) -> Self { match path.extension().unwrap().to_str().unwrap() { "gpl" => Self::from_gpl(path),