From bdec7e5d4f7eee469a9391424f9de75ca3eea012 Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Sun, 5 Apr 2020 22:26:47 +0100 Subject: [PATCH] optional hd image mode --- src/main.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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'); }