dedupe palette function

This commit is contained in:
Max Bradbury 2020-11-08 17:33:15 +00:00
parent 7ff67e51f8
commit fbe40fb866
2 changed files with 12 additions and 17 deletions

View File

@ -5,4 +5,3 @@
* noise reduction (remove lonely pixels)
* implement Atkinson and Bayer dithering options
* stats for added room (number of tiles)
* dedupe "palette from custom colours" functionality

View File

@ -185,19 +185,23 @@ fn image_to_base64(image: &DynamicImage) -> String {
format!("data:image/png;base64,{}", base64::encode(&bytes))
}
fn palette_from(bg: &bitsy_parser::Colour, fg: &bitsy_parser::Colour) -> bitsy_parser::Palette {
bitsy_parser::Palette {
id: "0".to_string(),
name: None,
colours: vec![
bg.clone(), fg.clone(), bitsy_parser::Colour { red: 0, green: 0, blue: 0 }
],
}
}
fn render_preview(state: &State) -> DynamicImage {
let mut buffer = state.image.as_ref().unwrap().clone().into_rgba();
let palette = match &state.palette {
SelectedPalette::None => bitsy_parser::mock::game_default().palettes[0].clone(),
SelectedPalette::Existing { id } => state.game.as_ref().unwrap().get_palette(id).unwrap().clone(),
SelectedPalette::New { background, foreground } => bitsy_parser::Palette {
id: "0".to_string(),
name: None,
colours: vec![
background.clone(), foreground.clone(), bitsy_parser::Colour { red: 0, green: 0, blue: 0 }
],
},
SelectedPalette::New { background, foreground } => palette_from(background, foreground),
};
let colour_map = crate::ColourMap::from(&palette);
@ -258,15 +262,7 @@ pub fn add_room() -> String {
SelectedPalette::None => bitsy_parser::mock::game_default().palettes[0].id.clone(),
SelectedPalette::Existing { id } => id.clone(),
SelectedPalette::New { background, foreground } => {
game.add_palette(bitsy_parser::Palette {
id: "0".to_string(),
name: None,
colours: vec![
background.clone(),
foreground.clone(),
bitsy_parser::Colour { red: 0, green: 0, blue: 0 }
],
})
game.add_palette(palette_from(background, foreground))
},
});