rework image
This commit is contained in:
parent
76eca72699
commit
8d8515bb8a
26
src/image.rs
26
src/image.rs
|
@ -1,22 +1,26 @@
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
pub struct Image {
|
pub struct Image {
|
||||||
pub pixels: Vec<u32>, // 64 for SD, 256 for HD
|
pub pixels: Vec<u8>, // 64 for SD, 256 for HD
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<String> for Image {
|
impl From<String> for Image {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(string: String) -> Image {
|
fn from(string: String) -> Image {
|
||||||
let string = string.replace("\n", "");
|
print!("image: \n{}", string);
|
||||||
let string = string.replace("NaN", "0");
|
let string = string.replace("NaN", "0");
|
||||||
let pixels: Vec<&str> = string.split("").collect();
|
let string = string.trim();
|
||||||
// the above seems to add an extra "" at the start and end of the vec, so strip them below
|
let lines: Vec<&str> = string.lines().collect();
|
||||||
let pixels = &pixels[1..(pixels.len() - 1)];
|
let dimension = lines.len();
|
||||||
let pixels: Vec<u32> = pixels
|
let mut pixels: Vec<u8> = Vec::new();
|
||||||
.iter()
|
|
||||||
.map(|&pixel|
|
for line in lines {
|
||||||
pixel.parse::<u32>().expect(&format!("Bad pixel in image: {}\n", pixel))
|
let line = &line[..dimension];
|
||||||
)
|
println!("line: {}", line);
|
||||||
.collect();
|
for char in line.chars().into_iter() {
|
||||||
|
println!("Char: {} value: {}", char, match char {'1' => 1, _ => 0});
|
||||||
|
pixels.push(match char {'1' => 1, _ => 0});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Image { pixels }
|
Image { pixels }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue