From 26090499e76b659a1211355936707b3c9cc37105 Mon Sep 17 00:00:00 2001 From: Corwin Date: Sat, 6 May 2023 20:31:43 +0100 Subject: [PATCH] fix image converter bug --- agb-image-converter/src/lib.rs | 4 ++-- agb-image-converter/src/palette16.rs | 19 ++++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/agb-image-converter/src/lib.rs b/agb-image-converter/src/lib.rs index c63c4656..c844673a 100644 --- a/agb-image-converter/src/lib.rs +++ b/agb-image-converter/src/lib.rs @@ -432,8 +432,8 @@ fn palette_tile_data( let mut tile_data = Vec::new(); - for image in images { - add_image_to_tile_data(&mut tile_data, image, optimiser, 0) + for (image_idx, image) in images.iter().enumerate() { + add_image_to_tile_data(&mut tile_data, image, optimiser, image_idx) } let tile_data = collapse_to_4bpp(&tile_data); diff --git a/agb-image-converter/src/palette16.rs b/agb-image-converter/src/palette16.rs index 2d384c69..03ae3a57 100644 --- a/agb-image-converter/src/palette16.rs +++ b/agb-image-converter/src/palette16.rs @@ -138,17 +138,7 @@ impl Palette16Optimiser { while !unsatisfied_palettes.is_empty() { let palette = self.find_maximal_palette_for(&unsatisfied_palettes); - for test_palette in unsatisfied_palettes.clone() { - if test_palette.is_satisfied_by(&palette) { - unsatisfied_palettes.remove(&test_palette); - } - } - - for (i, overall_palette) in self.palettes.iter().enumerate() { - if overall_palette.is_satisfied_by(&palette) { - assignments[i] = optimised_palettes.len(); - } - } + unsatisfied_palettes.retain(|test_palette| !test_palette.is_satisfied_by(&palette)); optimised_palettes.push(palette); @@ -157,6 +147,13 @@ impl Palette16Optimiser { } } + for (i, overall_palette) in self.palettes.iter().enumerate() { + assignments[i] = optimised_palettes + .iter() + .position(|palette| overall_palette.is_satisfied_by(palette)) + .unwrap(); + } + Palette16OptimisationResults { optimised_palettes, assignments,