enforced ASCII validation on '--map' flag

This commit is contained in:
Djairo Hougee 2023-02-08 22:09:18 +01:00
parent 2b9817080e
commit 529b6a61e2
2 changed files with 7 additions and 1 deletions

View File

@ -17,7 +17,6 @@ fn to_ascii(char_map: String, image: DynamicImage) -> Vec<Vec<Ascii>> {
for pixel in image.pixels() { for pixel in image.pixels() {
let ch = char_map.as_bytes()[((get_color(pixel.2) as f32-1.0)/255f32 * l) as usize]; let ch = char_map.as_bytes()[((get_color(pixel.2) as f32-1.0)/255f32 * l) as usize];
//fixme: might break with non-ASCII char_map
str.push(Ascii::new(ch, pixel.2[0], pixel.2[1], pixel.2[2])); str.push(Ascii::new(ch, pixel.2[0], pixel.2[1], pixel.2[2]));
if pixel.0 == image.width()-1 { if pixel.0 == image.width()-1 {

View File

@ -92,6 +92,13 @@ impl Cli {
exit(1); exit(1);
} }
} }
if let Some(map) = self.map.clone() {
if !map.is_ascii() {
error!("map can not contain non-ASCII characters!");
exit(1);
}
}
} }
pub fn init(&self) { pub fn init(&self) {