optional hd image mode
This commit is contained in:
parent
b7ff7c951c
commit
bdec7e5d4f
14
src/main.rs
14
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');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue