dedupe palette function
This commit is contained in:
parent
7ff67e51f8
commit
fbe40fb866
1
TODO.md
1
TODO.md
|
@ -5,4 +5,3 @@
|
||||||
* noise reduction (remove lonely pixels)
|
* noise reduction (remove lonely pixels)
|
||||||
* implement Atkinson and Bayer dithering options
|
* implement Atkinson and Bayer dithering options
|
||||||
* stats for added room (number of tiles)
|
* stats for added room (number of tiles)
|
||||||
* dedupe "palette from custom colours" functionality
|
|
||||||
|
|
28
src/lib.rs
28
src/lib.rs
|
@ -185,19 +185,23 @@ fn image_to_base64(image: &DynamicImage) -> String {
|
||||||
format!("data:image/png;base64,{}", base64::encode(&bytes))
|
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 {
|
fn render_preview(state: &State) -> DynamicImage {
|
||||||
let mut buffer = state.image.as_ref().unwrap().clone().into_rgba();
|
let mut buffer = state.image.as_ref().unwrap().clone().into_rgba();
|
||||||
|
|
||||||
let palette = match &state.palette {
|
let palette = match &state.palette {
|
||||||
SelectedPalette::None => bitsy_parser::mock::game_default().palettes[0].clone(),
|
SelectedPalette::None => bitsy_parser::mock::game_default().palettes[0].clone(),
|
||||||
SelectedPalette::Existing { id } => state.game.as_ref().unwrap().get_palette(id).unwrap().clone(),
|
SelectedPalette::Existing { id } => state.game.as_ref().unwrap().get_palette(id).unwrap().clone(),
|
||||||
SelectedPalette::New { background, foreground } => bitsy_parser::Palette {
|
SelectedPalette::New { background, foreground } => palette_from(background, foreground),
|
||||||
id: "0".to_string(),
|
|
||||||
name: None,
|
|
||||||
colours: vec![
|
|
||||||
background.clone(), foreground.clone(), bitsy_parser::Colour { red: 0, green: 0, blue: 0 }
|
|
||||||
],
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let colour_map = crate::ColourMap::from(&palette);
|
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::None => bitsy_parser::mock::game_default().palettes[0].id.clone(),
|
||||||
SelectedPalette::Existing { id } => id.clone(),
|
SelectedPalette::Existing { id } => id.clone(),
|
||||||
SelectedPalette::New { background, foreground } => {
|
SelectedPalette::New { background, foreground } => {
|
||||||
game.add_palette(bitsy_parser::Palette {
|
game.add_palette(palette_from(background, foreground))
|
||||||
id: "0".to_string(),
|
|
||||||
name: None,
|
|
||||||
colours: vec![
|
|
||||||
background.clone(),
|
|
||||||
foreground.clone(),
|
|
||||||
bitsy_parser::Colour { red: 0, green: 0, blue: 0 }
|
|
||||||
],
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue