Fix alpha not being considered when transparent_colour was absent

This commit is contained in:
Eievui 2023-01-21 14:12:56 -05:00
parent b76e7b9bf0
commit 43279e72c3
2 changed files with 7 additions and 7 deletions

View file

@ -386,7 +386,7 @@ fn add_image_to_tile_data(
for i in inner_x * 8..inner_x * 8 + 8 {
let colour = image.colour(x * tile_size + i, y * tile_size + j);
tile_data
.push(palette.colour_index(colour, optimiser.transparent_colour));
.push(palette.colour_index(colour));
}
}
}

View file

@ -41,15 +41,15 @@ impl Palette16 {
true
}
pub fn colour_index(&self, colour: Colour, transparent_colour: Option<Colour>) -> u8 {
let colour_to_search = match (transparent_colour, colour.is_transparent()) {
(Some(transparent_colour), true) => transparent_colour,
_ => colour,
};
pub fn colour_index(&self, colour: Colour) -> u8 {
// A transparent color is always index 0
if colour.is_transparent() {
return 0;
}
self.colours
.iter()
.position(|c| *c == colour_to_search)
.position(|c| *c == colour)
.unwrap_or_else(|| {
panic!(
"Can't get a colour index without it existing, looking for {:?}, got {:?}",