Slightly easier debugging

This commit is contained in:
Gwilym Inzani 2024-09-25 12:13:28 +01:00
parent edb628d0b2
commit 40987f8977
2 changed files with 19 additions and 7 deletions

View file

@ -1,6 +1,6 @@
use std::str::FromStr;
use std::{fmt, str::FromStr};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct Colour {
pub r: u8,
pub g: u8,
@ -8,6 +8,18 @@ pub struct Colour {
pub a: u8,
}
impl fmt::Debug for Colour {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "#{:02x}{:02x}{:02x}", self.r, self.g, self.b)?;
if self.a != 0xff {
write!(f, "{:02x}", self.a)?;
}
Ok(())
}
}
impl Colour {
pub fn from_rgb(r: u8, g: u8, b: u8, a: u8) -> Self {
Colour { r, g, b, a }
@ -55,7 +67,7 @@ impl quickcheck::Arbitrary for Colour {
vec![
Colour::from_rgb(0, 0, 0, 0),
Colour::from_rgb(self.r, self.g, self.b, 0),
self.clone(),
*self,
]
.into_iter(),
)

View file

@ -164,10 +164,6 @@ impl Palette16Optimiser {
let packed_palettes =
pagination_packing::overload_and_remove::<_, _, Vec<_>>(&palettes_to_optimise, 16);
if packed_palettes.len() > 16 {
return Err(DoesNotFitError(packed_palettes.len()));
}
let optimised_palettes = packed_palettes
.iter()
.map(|packed_palette| {
@ -176,6 +172,10 @@ impl Palette16Optimiser {
})
.collect::<Vec<_>>();
if optimised_palettes.len() > 16 {
return Err(DoesNotFitError(packed_palettes.len()));
}
let mut assignments = vec![0; self.palettes.len()];
for (i, overall_palette) in self.palettes.iter().enumerate() {