diff --git a/src/main.rs b/src/main.rs index 31802cd..43b2ec8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,9 @@ use std::fmt; use std::collections::HashMap; +const IMAGE_DIMENSION_SD: usize = 8; +const IMAGE_DIMENSION_HD: usize = 16; + #[derive(Eq, PartialEq)] struct Colour { red: u8, @@ -145,11 +148,16 @@ fn image_from_string(string: String) -> Image { } fn image_to_string(image: Image) -> String { - let mut string = String::new(); + image_to_string_opts(image, true) +} - for line in image.pixels.chunks(8) { +fn image_to_string_opts(image: Image, hd: bool) -> String { + let mut string = String::new(); + let chunk_size = if hd {IMAGE_DIMENSION_HD} else {IMAGE_DIMENSION_SD}; + + for line in image.pixels.chunks(chunk_size) { for pixel in line { - string.push(if *pixel {'1'} else {'0'}); + string.push(*pixel as char); } string.push('\n'); }