diff --git a/agb-image-converter/src/colour.rs b/agb-image-converter/src/colour.rs index cba2a831..3f12001e 100644 --- a/agb-image-converter/src/colour.rs +++ b/agb-image-converter/src/colour.rs @@ -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(), ) diff --git a/agb-image-converter/src/palette16.rs b/agb-image-converter/src/palette16.rs index a501374c..acdd4c0b 100644 --- a/agb-image-converter/src/palette16.rs +++ b/agb-image-converter/src/palette16.rs @@ -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::>(); + 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() {